// save xmas network project bool model::Network::saveFile(QUrl fileUrl) { auto project = dataControl->project(); std::string filename = fileUrl.isLocalFile() ? fileUrl.toLocalFile().toStdString() : fileUrl.fileName().toStdString(); project->saveNetwork(filename); return true; }
void TrackingAndDetection::runVideoFeed() { Mat currentFrame = this->videoInput->getNextFrame(); // check if no new frame available (ie. end of video reached) if (currentFrame.size().height == 0) { // save the results if ((inputType == FILE_INPUT) && (directoryOutput != "")) { mkdir((directoryOutput).c_str(), S_IRWXU); emit(saveNetwork(this->network, directoryOutput)); exit(EXIT_SUCCESS); } // loop through the video again if((inputType == FILE_INPUT) && (this->iteration < this->numIteration)) { this->videoInput->startCamera(); currentFrame = this->videoInput->getNextFrame(); Location location = ((VideoFileInput*)this->videoInput)->getInitialLocation(currentFrame); network->resetLocation(location); this->iteration = this->iteration + 1; } return; } Mat labFrame; cvtColor(currentFrame, labFrame, CV_RGB2Lab); if(state == TRACKING) { this->numberOfFrames++; this->detectObject(labFrame); emit(updateNumARBs(this->network->getNumberOfARBs())); } else { labFrame.copyTo(this->initialFrame); } emit(updateImage(currentFrame.data, currentFrame.cols, currentFrame.rows)); }
int main() { // input file stream std::string line; std::ifstream myfile; NeuralNetwork* nn; srand((unsigned int)time(0)); int training_label[TRAINING_SIZE]; float training_data[TRAINING_SIZE][INPUT_SIZE]; int testing_label[TESTING_SIZE]; float testing_data[TESTING_SIZE][INPUT_SIZE]; char* inputfile[]= { "data/forward.dat", "data/right.dat", "data/train_right2.dat", "data/train_reverse.dat", "data/train_reverse2.dat", "data/left.dat", "data/left2.dat" }; int classifications[NUM_TRAINING_FILES] = { FORWARD, RIGHT, RIGHT, REVERSE, REVERSE, LEFT, LEFT }; /******************************************************************************************************************** * Load the input data ********************************************************************************************************************/ int trn_idx = 0; int tst_idx = 0; for(int k = 0; k < NUM_TRAINING_FILES; k++) { myfile.open(inputfile[k]); for (int i = 0; i < TRAINING_SET_SIZE; i++) { for (int j = 0; j < INPUT_SIZE; j++) { std::getline(myfile, line); training_data[trn_idx][j] = strtof(line.c_str(), NULL); } training_label[trn_idx] = classifications[k]; trn_idx++; } for (int i = 0; i < TESTING_SET_SIZE; i++) { for (int j = 0; j < INPUT_SIZE; j++) { std::getline(myfile, line); testing_data[tst_idx][j] = strtof(line.c_str(), NULL); } testing_label[tst_idx] = classifications[k]; tst_idx++; } myfile.close(); myfile.clear(); } /******************************************************************************************************************** * instantiate the network ********************************************************************************************************************/ if (LOADNETWORK == 1) nn = loadNetwork("speech_weights.dat"); else nn = neuralNetwork(); /******************************************************************************************************************** * train the network, shift training/testing sets periodically to avoid overfitting ********************************************************************************************************************/ int j1, j2, temp; float temp_f; float* templ; float accuracy = 0; for (int x = 0; x < TRAINING_CYCLES && accuracy < DESIRED_ACCURACY; x++) { //move items between the training and testing sets for (int i = 0; i < 1000; i++) { j1 = rand() % (TRAINING_SIZE); j2 = rand() % (TESTING_SIZE); temp = training_label[j1]; training_label[j1] = testing_label[j2]; testing_label[j2] = temp; for (int k = 0; k < INPUT_SIZE; k++) { temp_f = training_data[j1][k]; training_data[j1][k] = testing_data[j2][k]; testing_data[j2][k] = temp_f; } } // "shuffle" the data order (it's not perfectly random but i don't care) for (int i = 0; i < 450; i++) { j1 = rand() % (TRAINING_SIZE); j2 = rand() % (TRAINING_SIZE); temp = training_label[j1]; training_label[j1] = training_label[j2]; training_label[j2] = temp; for (int k = 0; k < INPUT_SIZE; k++) { temp_f = training_data[j1][k]; training_data[j1][k] = training_data[j2][k]; training_data[j2][k] = temp_f; } } for (int i = 0; i < 50; i++) { j1 = rand() % (TESTING_SIZE); j2 = rand() % (TESTING_SIZE); temp = testing_label[j1]; testing_label[j1] = testing_label[j2]; testing_label[j2] = temp; for (int k = 0; k < INPUT_SIZE; k++) { temp_f = testing_data[j1][k]; testing_data[j1][k] = testing_data[j2][k]; testing_data[j2][k] = temp_f; } } std::cout << "***** training iteration " << x << " *****\n"; accuracy = trainNetwork(nn, training_data, training_label, TRAINING_SIZE, testing_data, testing_label, TESTING_SIZE); } if (LOADNETWORK == 0) { saveNetwork(nn, "speech_weights.dat"); saveNetworkHeaderFile(nn, "speech_weights.h"); } myfile.close(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); this->imageWidget = new QtWidgetImageDisplay(); this->setCentralWidget(this->imageWidget); // connect all the menu buttons to this class this->connect(ui->actionWebcam, SIGNAL(triggered()), this, SLOT(setVideoInputToWebcam())); this->connect(ui->actionFile, SIGNAL(triggered()), this, SLOT(setVideoInputToFile())); this->connect(ui->actionRotation, SIGNAL(triggered()), this, SLOT(useRotationChanged())); this->connect(ui->actionScale, SIGNAL(triggered()), this, SLOT(useScaleChanged())); this->connect(ui->actionPredict_Location, SIGNAL(triggered()), this, SLOT(usePredictedLocationChanged())); //this->connect(ui->actionUse_Most_Likely_ARBs, SIGNAL(triggered()), this, SLOT(useMostLikelyAppearancesChanged())); /*this->connect(ui->actionAll_ARBs, SIGNAL(triggered()), this, SLOT(whichARBsToSearchWithChangedToALL())); this->connect(ui->actionAbove_Avarage_RL, SIGNAL(triggered()), this, SLOT(whichARBsToSearchWithChangedToAboveAverageRL())); this->connect(ui->actionLatest_Highest_RL, SIGNAL(triggered()), this, SLOT(whichARBsToSearchWithChangedToLatestAndHighestRL())); this->connect(ui->actionLatest_Connected, SIGNAL(triggered()), this, SLOT(whichARBsToSearchWithChangedToLatestAndConnected())); this->connect(ui->actionHighest_Connected, SIGNAL(triggered()), this, SLOT(whichARBsToSearchWithChangedToHighestAndConnected())); */ this->connect(ui->actionOT, SIGNAL(triggered()), this, SLOT(changeObjectThreshold())); this->connect(ui->actionST, SIGNAL(triggered()), this, SLOT(changeStimulationThreshold())); this->connect(ui->actionSSD, SIGNAL(triggered()), this, SLOT(distanceMeasureChangedToSSD())); this->connect(ui->actionEuclidean, SIGNAL(triggered()), this, SLOT(distanceMeasureChangedToEuclidean())); //this->connect(ui->actionPrint, SIGNAL(triggered()), this->imageWidget, SLOT(printNumberArbsInNetwork())); this->connect(ui->actionSave_Network, SIGNAL(triggered()), this->imageWidget, SLOT(saveNetwork())); this->connect(ui->actionReset, SIGNAL(triggered()), this, SLOT(reset())); }