代码地址如下:
http://www.demodashi.com/demo/11138.html
//Set neuron number of every layervector<int> layer_neuron_num = { 784,100,10 };// Initialise Net and weightsNet net;net.initNet(layer_neuron_num);net.initWeights(0, 0., 0.01);net.initBias(Scalar(0.5));
#include"../include/Net.h"
//<opencv2\opencv.hpp>using namespace std;
using namespace cv;
using namespace liu;int main(int argc, char *argv[])
{//Set neuron number of every layervector<int> layer_neuron_num = { 784,100,10 };// Initialise Net and weightsNet net;net.initNet(layer_neuron_num);net.initWeights(0, 0., 0.01);net.initBias(Scalar(0.5));//Get test samples and test samples Mat input, label, test_input, test_label;int sample_number = 800;get_input_label("data/input_label_1000.xml", input, label, sample_number);get_input_label("data/input_label_1000.xml", test_input, test_label, 200, 800);//Set loss threshold,learning rate and activation functionfloat loss_threshold = 0.5;net.learning_rate = 0.3;net.output_interval = 2;net.activation_function = "sigmoid";//Train,and draw the loss curve(cause the last parameter is ture) and test the trained netnet.train(input, label, loss_threshold, true);net.test(test_input, test_label);//Save the modelnet.save("models/model_sigmoid_800_200.xml");getchar();return 0;
}
#include"../include/Net.h"
//<opencv2\opencv.hpp>using namespace std;
using namespace cv;
using namespace liu;int main(int argc, char *argv[])
{//Get test samples and the label is 0--1Mat test_input, test_label;int sample_number = 200;int start_position = 800;get_input_label("data/input_label_1000.xml", test_input, test_label, sample_number, start_position);//Load the trained net and test.Net net;net.load("models/model_sigmoid_800_200.xml");net.test(test_input, test_label);getchar();return 0;
}
这是以部分minist数据测试的效果图。同时还能实时输出loss值。
C++从零实现简单深度神经网络(基于OpenCV)
代码地址如下:
http://www.demodashi.com/demo/11138.html注:本文著作权归作者,由demo大师发表,拒绝转载,转载需要作者授权
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态