void runMnist(){ const int nclasses = 10; /*state and cublas handle*/ cublasHandle_t handle; init(handle); /*read the data from disk*/ cuMatrixVector<double>trainX; cuMatrixVector<double>testX; cuMatrix<double>* trainY, *testY; Config::instance(); readMnistData(trainX, trainY, "mnist/train-images.idx3-ubyte", "mnist/train-labels.idx1-ubyte", 60000, 1); readMnistData(testX , testY, "mnist/t10k-images.idx3-ubyte", "mnist/t10k-labels.idx1-ubyte", 10000, 1); /*build CNN net*/ int ImgSize = trainX[0]->rows; int nsamples = trainX.size(); std::vector<cuCvl> ConvLayers; std::vector<cuNtw> HiddenLayers; cuSMR smr; int batch = 200; double start,end; int cmd; cuInitDistortionMemery(batch, ImgSize); printf("random init input 0\nRead from file input 1\n"); scanf("%d", &cmd); if(cmd == 0) cuConvNetInitPrarms(ConvLayers, HiddenLayers, smr, ImgSize, nsamples, nclasses); else if(cmd == 1) cuReadConvNet(ConvLayers, HiddenLayers, smr, ImgSize, nsamples, "net.txt", nclasses); cuInitCNNMemory(batch, trainX, testX, ConvLayers,HiddenLayers, smr, ImgSize, nclasses); start = clock(); cuTrainNetwork(trainX, trainY, ConvLayers, HiddenLayers, smr, 4e-4, testX, testY, nsamples, batch, ImgSize, nclasses, handle); end = clock(); printf("trainning time %lf\n", (end - start) / CLOCKS_PER_SEC); }
void runChinese() { const int nclasses = 10; /*state and cublas handle*/ cublasHandle_t handle; init(handle); /*read the data from disk*/ cuMatrixVector<float> trainX; cuMatrixVector<float> testX; cuMatrix<int>* trainY, *testY; readChineseData(trainX, testX, trainY, testY); Config::instance()->initPath("Config/ChineseConfig.txt"); /*build CNN net*/ int ImgSize = trainX[0]->rows; int crop = Config::instance()->getCrop(); int nsamples = trainX.size(); int batch = Config::instance()->getBatchSize(); float start, end; int cmd; cuInitDistortionMemery(batch, ImgSize - crop); printf( "1. random init weight\n2. Read weight from file\nChoose the way to init weight:"); if(g_argv.size() >= 2) cmd = g_argv[1]; else { if(1 != scanf("%d", &cmd)){ LOG("scanf fail", "result/log.txt"); } } if (cmd == 2) cuReadConvNet(ImgSize - crop, "Result/checkPoint.txt", nclasses); buildNetWork(trainX.size(), testX.size()); /*learning rate*/ std::vector<float>nlrate; std::vector<float>nMomentum; std::vector<int>epoCount; float r = 0.05; float m = 0.90; int e = 50; for(int i = 0; i < 20; i++){ nlrate.push_back(r); nMomentum.push_back(m); epoCount.push_back(e); r = r * 0.90; m = m + 0.005; if(m >= 1.0) m = 0.99; } start = clock(); cuTrainNetwork(trainX, trainY, testX, testY, batch, ImgSize - crop, nclasses, nlrate, nMomentum, epoCount, handle); end = clock(); char logStr[1024]; sprintf(logStr, "trainning time hours = %f\n", (end - start) / CLOCKS_PER_SEC / 3600); LOG(logStr, "Result/log.txt"); }
void runMnist(){ const int nclasses = 10; /*state and cublas handle*/ cublasHandle_t handle; init(handle); /*read the data from disk*/ cuMatrixVector<float>trainX; cuMatrixVector<float>testX; cuMatrix<int>* trainY, *testY; Config::instance()->initPath("Config/MnistConfig.txt"); readMnistData(trainX, trainY, "mnist/train-images-idx3-ubyte", "mnist/train-labels-idx1-ubyte", 60000, 1); readMnistData(testX , testY, "mnist/t10k-images-idx3-ubyte", "mnist/t10k-labels-idx1-ubyte", 10000, 1); MemoryMonitor::instance()->printCpuMemory(); MemoryMonitor::instance()->printGpuMemory(); /*build CNN net*/ int ImgSize = trainX[0]->rows; Config::instance()->setImageSize(ImgSize - Config::instance()->getCrop()); int crop = Config::instance()->getCrop(); int nsamples = trainX.size(); int batch = Config::instance()->getBatchSize(); float start,end; int cmd; cuInitDistortionMemery(batch, ImgSize - crop); printf("1. random init weight\n2. Read weight from file\nChoose the way to init weight:"); if(g_argv.size() >= 2) cmd = g_argv[1]; else if(1 != scanf("%d", &cmd)){ LOG("scanf fail", "result/log.txt"); } buildNetWork(trainX.size(), testX.size()); if(cmd == 2) cuReadConvNet(ImgSize - crop, "Result/checkPoint.txt", nclasses); /*learning rate*/ std::vector<float>nlrate; std::vector<float>nMomentum; std::vector<int>epoCount; nlrate.push_back(0.05f); nMomentum.push_back(0.90f); epoCount.push_back(15); nlrate.push_back(0.04f); nMomentum.push_back(0.90f); epoCount.push_back(15); nlrate.push_back(0.03f); nMomentum.push_back(0.90f); epoCount.push_back(15); nlrate.push_back(0.02f); nMomentum.push_back(0.90f); epoCount.push_back(15); nlrate.push_back(0.01f); nMomentum.push_back(0.90f); epoCount.push_back(15); nlrate.push_back(0.009f); nMomentum.push_back(0.90f); epoCount.push_back(15); nlrate.push_back(0.008f); nMomentum.push_back(0.90f); epoCount.push_back(15); nlrate.push_back(0.007f); nMomentum.push_back(0.90f); epoCount.push_back(15); nlrate.push_back(0.006f); nMomentum.push_back(0.90f); epoCount.push_back(15); nlrate.push_back(0.005f); nMomentum.push_back(0.90f); epoCount.push_back(15); nlrate.push_back(0.004f); nMomentum.push_back(0.90f); epoCount.push_back(15); nlrate.push_back(0.003f); nMomentum.push_back(0.90f); epoCount.push_back(15); start = clock(); cuTrainNetwork(trainX, trainY, testX, testY, batch, ImgSize - crop, nclasses, nlrate, nMomentum, epoCount, handle); end = clock(); char logStr[1024]; sprintf(logStr, "trainning time hours = %f\n", (end - start) / CLOCKS_PER_SEC / 3600); LOG(logStr, "Result/log.txt"); }