MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindowClass) { ui->setupUi(this); ui->statusBar->showMessage(QString::fromStdString(dtnet::version())); ui->dockProperties->setObjectName("NetworkProperties"); ui->dockProperties->setWindowTitle(tr("Network Properties")); networkToolBox = new QToolBox(); ui->dockProperties->setWidget(networkToolBox); tabWidget = new QTabWidget(); networkView = new NetworkView( NULL ); networkTab = tabWidget->addTab(networkView, QString("Network View")); voltageLabel = new QLabel; rtvoltageTab = tabWidget->addTab(voltageLabel, QString("Real-Time Voltage")); setCentralWidget(tabWidget); // Setup Signals and Slots QObject::connect(&ws, SIGNAL(networkChanged()), this, SLOT(loadNetwork()) ); QObject::connect(&ws, SIGNAL(trialChanged()), this, SLOT(loadNetwork()) ); // We can't run simulations by default ui->actionRun_Simulation->setEnabled( false ); }
// // Creating Neural Network from file // void NN_File::loadFromFile(const std::string & fileName) { TiXmlDocument doc(fileName); doc.LoadFile(); TiXmlElement * pRoot = doc.RootElement(); loadNetwork(pRoot); loadWeights(pRoot->FirstChildElement("weights")); }
// // Training the Neural Network // void NN_File::train(const std::string & trainingSet) { TiXmlDocument doc(trainingSet); doc.LoadFile(); TiXmlElement * pRoot = doc.RootElement(); loadNetwork(pRoot->FirstChildElement("neuralnetwork")); randomWeights(); double minError; pRoot->Attribute("error", &minError); minError /= 100.0; // Training float error = 100.0; while( error > minError ) { error = train(pRoot); std::cout << "Error : " << error *100 << std::endl; } }
void MosaicControlNetTool::fromPvl(const PvlObject &obj) { m_controlNetFile = obj["FileName"][0]; if (m_controlNetFile == "Null") m_controlNetFile = ""; if (obj.hasKeyword("Movement")) { m_movementArrowColorSource = fromMovementColorSourceString(obj["Movement"]); } if (obj.hasKeyword("MovementColorMaxMeasureCount")) { m_measureCount = toInt(obj["MovementColorMaxMeasureCount"][0]); } if (obj.hasKeyword("MovementColorMaxResidualMagnitude")) { m_residualMagnitude = toDouble(obj["MovementColorMaxResidualMagnitude"][0]); } loadNetwork(); if (m_controlNetGraphics && m_displayControlNetButton) { m_displayControlNetButton->setChecked( toBool(obj["Visible"][0]) ); displayControlNet(); } }
QuickStartWizard::QuickStartWizard(QWidget *parent) : QDialog(parent) { ui.setupUi(this); ui.headerFrame->setHeaderImage(QPixmap(":/images/rs_wizard.png")); ui.headerFrame->setHeaderText("RetroShare"); ui.pagesWizard->setCurrentIndex(0); loadNetwork(); loadShare(); loadGeneral(); // ui.checkBoxF2FRouting->setChecked(true) ; // ui.checkBoxF2FRouting->setEnabled(false) ; connect( ui.netModeComboBox, SIGNAL( activated ( int ) ), this, SLOT( toggleUPnP( ) ) ); // connect( ui.checkBoxTunnelConnection, SIGNAL( toggled( bool ) ), this, SLOT( toggleTunnelConnection(bool) ) ); // bool b = rsPeers->getAllowTunnelConnection() ; // ui.checkBoxTunnelConnection->setChecked(b) ; QHeaderView_setSectionResizeModeColumn(ui.shareddirList->horizontalHeader(), 0, QHeaderView::Stretch); QHeaderView_setSectionResizeModeColumn(ui.shareddirList->horizontalHeader(), 2, QHeaderView::Interactive); ui.shareddirList->horizontalHeader()->resizeSection( 0, 360 ); ui.shareddirList->horizontalHeader()->setStretchLastSection(false); /* Hide platform specific features */ #ifndef Q_WS_WIN ui.checkBoxRunRetroshareAtSystemStartup->setVisible(false); ui.chkRunRetroshareAtSystemStartupMinimized->setVisible(false); #endif }
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(); }
void QuickStartWizard::saveChanges() { QString str; //bool saveAddr = false; RsPeerDetails detail; RsPeerId ownId = rsPeers->getOwnId(); if (!rsPeers->getPeerDetails(ownId, detail)) { return; } /* Check if netMode has changed */ int netMode = 0; int netIndex = ui.netModeComboBox->currentIndex(); std::cerr << "ui.netModeComboBox->currentIndex()" << ui.netModeComboBox->currentIndex() << std::endl; switch(netIndex) { case 2: netMode = RS_NETMODE_EXT; break; case 1: netMode = RS_NETMODE_UDP; break; default: case 0: netMode = RS_NETMODE_UPNP; break; } rsPeers->setNetworkMode(ownId, netMode); /* Check if vis has changed */ uint16_t vs_disc = 0; uint16_t vs_dht = 0; switch(ui.discoveryComboBox->currentIndex()) { case 0: vs_disc = RS_VS_DISC_FULL; vs_dht = RS_VS_DHT_FULL; break; case 1: vs_disc = RS_VS_DISC_FULL; vs_dht = RS_VS_DHT_OFF; break; case 2: vs_disc = RS_VS_DISC_OFF; vs_dht = RS_VS_DHT_FULL; break; case 3: default: vs_disc = RS_VS_DISC_OFF; vs_dht = RS_VS_DHT_OFF; break; } if ((vs_disc != detail.vs_disc) || (vs_dht != detail.vs_dht)) { rsPeers->setVisState(ownId, vs_disc, vs_dht); } /*if (0 != netIndex) { saveAddr = true; }*/ /*if (saveAddr) { rsPeers->setLocalAddress(rsPeers->getOwnId(), ui.localAddress->text().toStdString(), ui.localPort->value()); rsPeers->setExtAddress(rsPeers->getOwnId(), ui.extAddress->text().toStdString(), ui.extPort->value()); }*/ rsConfig->SetMaxDataRates( ui.doubleSpinBoxDownloadSpeed->value(), ui.doubleSpinBoxUploadSpeed->value() ); loadNetwork(); }
int main(int argc, char** argv) { THCState *state = (THCState*)malloc(sizeof(THCState)); THCudaInit(state); if(argc < 3) { std::cout << "arguments: [network] [image1] [image2]\n"; return 1; } const char *network_path = argv[1]; auto net = loadNetwork(state, network_path); // load the images cv::Mat ima = cv::imread(argv[2]); cv::Mat imb = cv::imread(argv[3]); if(ima.empty() || imb.empty()) { std::cout << "images not found\n"; return 1; } cv::Mat ima_gray, imb_gray; cv::cvtColor(ima, ima_gray, cv::COLOR_BGR2GRAY); cv::cvtColor(imb, imb_gray, cv::COLOR_BGR2GRAY); // Here we set min_area parameter to a bigger value, like that minimal size // of a patch will be around 11x11, because the network was trained on bigger patches // this parameter is important in practice cv::Ptr<cv::MSER> detector = cv::MSER::create(5, 620); std::vector<cv::KeyPoint> kpa, kpb; detector->detect(ima_gray, kpa); detector->detect(imb_gray, kpb); std::cout << "image A MSER points detected: " << kpa.size() << std::endl; std::cout << "image B MSER points detected: " << kpb.size() << std::endl; std::vector<cv::Mat> patches_a, patches_b; extractPatches(ima_gray, kpa, patches_a); extractPatches(imb_gray, kpb, patches_b); cv::Mat descriptors_a, descriptors_b; extractDescriptors(state, net, patches_a, descriptors_a); extractDescriptors(state, net, patches_b, descriptors_b); cv::FlannBasedMatcher matcher; std::vector<cv::DMatch> matches; matcher.match( descriptors_a, descriptors_b, matches ); double max_dist = 0; double min_dist = 100; //-- Quick calculation of max and min distances between keypoints for( int i = 0; i < descriptors_a.rows; i++ ) { double dist = matches[i].distance; if( dist < min_dist ) min_dist = dist; if( dist > max_dist ) max_dist = dist; } printf("-- Max dist : %f \n", max_dist ); printf("-- Min dist : %f \n", min_dist ); std::vector<cv::DMatch> good_matches; for( int i = 0; i < descriptors_a.rows; i++ ) { if( matches[i].distance <= std::max(4*min_dist, 0.02) ) { good_matches.push_back( matches[i]); } } //-- Draw only "good" matches float f = 0.25; cv::resize(ima, ima, cv::Size(), f, f); cv::resize(imb, imb, cv::Size(), f, f); for(auto &it: kpa) { it.pt *= f; it.size *= f; } for(auto &it: kpb) { it.pt *= f; it.size *= f; } cv::Mat img_matches; cv::drawMatches( ima, kpa, imb, kpb, good_matches, img_matches, cv::Scalar::all(-1), cv::Scalar::all(-1), std::vector<char>(), cv::DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS ); for(auto &it : kpa) cv::circle(ima, cv::Point(it.pt.x, it.pt.y), it.size, cv::Scalar(255,255,0)); for(auto &it : kpb) cv::circle(imb, cv::Point(it.pt.x, it.pt.y), it.size, cv::Scalar(255,255,0)); cv::imshow("matches", img_matches); //cv::imshow("keypoints image 1", ima); //cv::imshow("keypoints image 2", imb); cv::waitKey(); THCudaShutdown(state); return 0; }
/** * Constructs a new LoadRecentNetworkAction. */ LoadRecentNetworkAction::LoadRecentNetworkAction(const QString &fileName, NeuralNetworkEditor *owner) : QAction(fileName, 0), mFileName(fileName), mOwner(owner) { connect(this, SIGNAL(triggered()), this, SLOT(loadNetwork())); }