void trainNetwork(Network *nn){ // open MNIST files FILE *imageFile, *labelFile; imageFile = openMNISTImageFile(MNIST_TRAINING_SET_IMAGE_FILE_NAME); labelFile = openMNISTLabelFile(MNIST_TRAINING_SET_LABEL_FILE_NAME); int errCount = 0; // Loop through all images in the file for (int imgCount=0; imgCount<MNIST_MAX_TRAINING_IMAGES; imgCount++){ // Reading next image and its corresponding label MNIST_Image img = getImage(imageFile); MNIST_Label lbl = getLabel(labelFile); // Convert the MNIST image to a standardized vector format and feed into the network Vector *inpVector = getVectorFromImage(&img); feedInput(nn, inpVector); // Feed forward all layers (from input to hidden to output) calculating all nodes' output feedForwardNetwork(nn); // Back propagate the error and adjust weights in all layers accordingly backPropagateNetwork(nn, lbl); // Classify image by choosing output cell with highest output int classification = getNetworkClassification(nn); if (classification!=lbl) errCount++; // Display progress during training displayTrainingProgress(imgCount, errCount, 3,5); // displayImage(&img, lbl, classification, 7,6); } // Close files fclose(imageFile); fclose(labelFile); }
void AudioConverter::feedDecoder(AudioConverterComplexInputDataProc dataProc, void* opaque, AVFrame* srcaudio) { int gotFrame, err; do { // Read input if (!m_avpkt.size) { UInt32 numDataPackets = 0; OSStatus err = feedInput(dataProc, opaque, numDataPackets); if (err != noErr) throw err; if (!m_avpkt.size) // numDataPackets cannot be trusted break; } err = avcodec_decode_audio4(m_decoder, srcaudio, &gotFrame, &m_avpkt); if (err < 0) throw std::runtime_error("avcodec_decode_audio4() failed"); m_avpkt.size -= err; m_avpkt.data += err; if (gotFrame) { if (!m_resampler) setupResampler(srcaudio); // Resample PCM err = avresample_convert(m_resampler, nullptr, 0, 0, srcaudio->data, 0, srcaudio->nb_samples); if (err < 0) throw std::runtime_error("avresample_convert() failed"); } } while (!gotFrame); }
void AntTweakBarSystem::process() { feedInput(); }