Example #1
0
int main() {
    cv::Mat img = util::in();
    auto vec = mat_to_vector( img );

    FANN::neural_net nn;
    nn.create_from_file( "neural.net" );
    auto result = nn.run( vec.data() );

    std::cout << "Dog index: " << result[0] << '\n';
    std::cout << "Human index: " << result[1] << '\n';
}
Example #2
0
void translate_wav(WAVFile input)
{
    double *in;
    fftw_complex *out;
    fftw_complex *in_back;
    double *out_back;
    fftw_plan plan;
    fftw_plan plan_back;

    int length = input.m_data_header.sub_chunk_2_size;
    in = (double*)fftw_malloc(sizeof(double)*samples_per_segment);
    out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*samples_per_segment/2+1);
    in_back = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*samples_per_segment/2+1);
    out_back = (double*)fftw_malloc(sizeof(double)*samples_per_segment+2);

    plan = fftw_plan_dft_r2c_1d(samples_per_segment, in, out, FFTW_ESTIMATE);
    plan_back = fftw_plan_dft_c2r_1d(samples_per_segment+1, in_back, out_back, FFTW_ESTIMATE);

    FANN::neural_net net;
    net.create_from_file("net.net");
    
    short outbuffer[(((length/2)/samples_per_segment)+1)*samples_per_segment];

    int sample_number = 0;
    while (sample_number < length/2) {
        for (int i = 0; i < samples_per_segment; i++) {
            if (sample_number+i >= length/2) {
                break;
            }
            in[i] = (double)input.m_data.PCM16[sample_number+i]/((double)(65536/2));
        }

        fftw_execute(plan);

        float *input_train = (float*)malloc(sizeof(float)*samples_per_segment/2+1);
        for (int i = 0; i < samples_per_segment/2+1; i++) {
            input_train[i] = out[0][i];
        }

        // Use neural net to translate voice
        std::cout << "outputting data\n";
        float *out_net = net.run(input_train);

        for (int i = 0; i < samples_per_segment/2+1; i++) {
            in_back[0][i] = out_net[i];
            in_back[1][i] = out_net[i+samples_per_segment/2+1];
            //in_back[0][i] = out[0][i];
            //in_back[1][i] = out[1][i];
        }

        memset(out_back, 0, sizeof(double)*samples_per_segment);
        fftw_execute(plan_back);

        for (int i = 0; i < samples_per_segment; i++) {
            outbuffer[sample_number+i] = ((out_back[i])/samples_per_segment)*(65536.f/2.f);
            //std::cout << ((out_back[i])/(float)samples_per_segment)*(65536.f/2.f)<<"\n";//outbuffer[sample_number+i] << "\n";
        }

        sample_number += samples_per_segment;
    }
    WAVFile output_wav(outbuffer, length, 16);
    output_wav.writeToFile("output.wav");
}