void FFN< LayerTypes, OutputLayerType, InitializationRuleType, PerformanceFunction >::Predict(arma::mat& predictors, arma::mat& responses) { deterministic = true; arma::mat responsesTemp; ResetParameter(network); Forward(arma::mat(predictors.colptr(0), predictors.n_rows, 1, false, true), network); OutputPrediction(responsesTemp, network); responses = arma::mat(responsesTemp.n_elem, predictors.n_cols); responses.col(0) = responsesTemp.col(0); for (size_t i = 1; i < predictors.n_cols; i++) { Forward(arma::mat(predictors.colptr(i), predictors.n_rows, 1, false, true), network); responsesTemp = arma::mat(responses.colptr(i), responses.n_rows, 1, false, true); OutputPrediction(responsesTemp, network); responses.col(i) = responsesTemp.col(0); } }
double CNN< LayerTypes, OutputLayerType, InitializationRuleType, PerformanceFunction >::Evaluate(const arma::mat& /* unused */, const size_t i, const bool deterministic) { this->deterministic = deterministic; ResetParameter(network); Forward(predictors.slices(i, (i + 1) * sampleSize - 1), network); return OutputError(arma::mat(responses.colptr(i), responses.n_rows, 1, false, true), error, network); }
double RNN< LayerTypes, OutputLayerType, InitializationRuleType, PerformanceFunction >::Evaluate(const arma::mat& /* unused */, const size_t i, const bool deterministic) { this->deterministic = deterministic; arma::mat input = arma::mat(predictors.colptr(i), predictors.n_rows, 1, false, true); arma::mat target = arma::mat(responses.colptr(i), responses.n_rows, 1, false, true); // Initialize the activation storage only once. if (activations.empty()) InitLayer(input, target, network); double networkError = 0; seqLen = input.n_rows / inputSize; ResetParameter(network); error = arma::mat(outputSize, outputSize < target.n_elem ? seqLen : 1); // Iterate through the input sequence and perform the feed forward pass. for (seqNum = 0; seqNum < seqLen; seqNum++) { // Perform the forward pass and save the activations. Forward(input.rows(seqNum * inputSize, (seqNum + 1) * inputSize - 1), network); SaveActivations(network); // Retrieve output error of the subsequence. if (seqOutput) { arma::mat seqError = error.unsafe_col(seqNum); arma::mat seqTarget = target.submat(seqNum * outputSize, 0, (seqNum + 1) * outputSize - 1, 0); networkError += OutputError(seqTarget, seqError, network); } } // Retrieve output error of the complete sequence. if (!seqOutput) return OutputError(target, error, network); return networkError; }
//创建参数 bool CServiceParameter::CreateParameter(LPCTSTR pszModuleName) { //重置参数 ResetParameter(); //加载模块 if (LoadGameServiceModule(pszModuleName)==false) { AfxMessageBox(TEXT("“服务组件不存在”或“无法识别”,无法创建游戏房间!"),MB_ICONINFORMATION); return false; } //配置参数 INT_PTR nResult=DoModal(); //释放模块 FreeGameServiceModule(); return (nResult==IDOK); }
void CNN< LayerTypes, OutputLayerType, InitializationRuleType, PerformanceFunction >::Predict(arma::cube& predictors, arma::mat& responses) { deterministic = true; arma::mat responsesTemp; ResetParameter(network); Forward(predictors.slices(0, sampleSize - 1), network); OutputPrediction(responsesTemp, network); responses = arma::mat(responsesTemp.n_elem, predictors.n_slices); responses.col(0) = responsesTemp.col(0); for (size_t i = 1; i < (predictors.n_slices / sampleSize); i++) { Forward(predictors.slices(i, (i + 1) * sampleSize - 1), network); responsesTemp = arma::mat(responses.colptr(i), responses.n_rows, 1, false, true); OutputPrediction(responsesTemp, network); responses.col(i) = responsesTemp.col(0); } }
//通用的初始化代码 //初始化PCI1761、数据库、根据参数将系统切换到真实/虚拟相机模式 //真实模式下调用TiggerStartWatch,开启监视线程 void ControllerModel::baseInit() { stringstream ss; //初始化PCI1761 if (IsRealModel) { if (!pci1761.init()) { pci1761Inited = false; } else pci1761Inited = true; } // 数据库配置初始化 if (1 == 1) { int accEnable = 0; SettingHelper::GetKeyInt("DATABASE", "ACCDB_ENABLE", accEnable);//读取是否启用数据库模块 ss.clear(); ss << "ACCDB_ENABLE = " << accEnable << endl; MFCConsole::Output(ss.str()); if (accEnable != 0) { string db_path; bool accConnFlag = false; if (SettingHelper::GetKeyString("DATABASE", "ACCDB_PATH", db_path))//读取数据库所在路径 { accConnFlag = Statistics::InitDate(db_path); MFCConsole::Output("db_path:"); MFCConsole::Output(db_path); MFCConsole::Output("\r\n"); } else { accConnFlag = Statistics::InitDate("src//..//瓷砖缺陷检测数据库.mdb"); SettingHelper::AddKey("DATABASE", "ACCDB_PATH", "src//..//瓷砖缺陷检测数据库.mdb"); MFCConsole::Output("db_path:src//..//瓷砖缺陷检测数据库.mdb\r\n"); } // 统计数据初始化 if (accConnFlag) spotsMainView->UpdateStatistics(); else AfxMessageBox(L"无法连接到数据库!"); } } // 初始化工作线程 if (e2vInited && pci1761Inited) { //若为真实相机模式,则实例化两个工人,并启动触发器监视进程 //初始化工人 worker1 = new Worker("worker1:"); worker2 = new Worker("worker2:"); worker1->P_Controller = this; worker2->P_Controller = this; TiggerStartWatch(); spotsMainView->SwitchModel2Virtual(false); MFCConsole::Output("已切换到真实相机模式。\r\n"); } else { PauseFlag = true; if (IsRealModel) { IsRealModel = 0; if (!e2vInited && !pci1761Inited) AfxMessageBox(L"线阵相机&pci1761初始化失败!已切换到虚拟相机模式。"); else if (!pci1761Inited) AfxMessageBox(L"pci1761初始化失败!已切换到虚拟相机模式。"); else if (!e2vInited) AfxMessageBox(L"线阵相机初始化失败!已切换到虚拟相机模式。"); } else MFCConsole::Output("已切换到虚拟相机模式。\r\n"); //若为虚拟相机模式,则实例化虚拟相机类与1个工人 //开启虚拟相机 cv::Mat virtualImg; worker1 = new Worker("Virtual Worker"); worker1->image = virtualImg; worker1->P_Controller = this; spotsMainView->SwitchModel2Virtual(true); } //读取参数配置 //设置工人算法参数 ResetParameter(); if (pci1761Inited) { //初始化面阵相机 if (MainHueScanner::Enabled) { P_mainHueScanner = new MainHueScanner(this); if (!P_mainHueScanner->HasInited) { delete P_mainHueScanner; P_mainHueScanner = NULL; AfxMessageBox(L"未能初始化面阵相机,该模块被禁用!"); } } } //初始化UI cv::Mat white(2, 2, CV_8U, cv::Scalar(255)); logImg.InitDrawingBoard(); spotsMainView->ShowBigImg(white); spotsMainView->ShowLogImg(logImg.DrawingBoard); }