CNN代码系列之训练初始化(三)
来源:互联网 发布:92game源码仿17173 编辑:程序博客网 时间:2024/06/05 20:20
本博客为CNN卷积代码系列之训练初始化。
注意:本博客是系列博客,请链接上一博客http://blog.csdn.net/samylee/article/details/69471988
CNN.hpp定义网络参数:
#ifndef _CNN_HPP_#define _CNN_HPP_#include <vector>namespace ANN {#define width_image_input_CNN32 //归一化图像宽#define height_image_input_CNN32 //归一化图像高#define width_image_C1_CNN28#define height_image_C1_CNN28#define width_image_S2_CNN14#define height_image_S2_CNN14#define width_image_C3_CNN10#define height_image_C3_CNN10#define width_image_S4_CNN5#define height_image_S4_CNN5#define width_image_C5_CNN1#define height_image_C5_CNN1#define width_image_output_CNN1#define height_image_output_CNN1#define width_kernel_conv_CNN5 //卷积核大小#define height_kernel_conv_CNN5#define width_kernel_pooling_CNN2#define height_kernel_pooling_CNN2#define size_pooling_CNN2#define num_map_input_CNN1 //输入层map个数#define num_map_C1_CNN6 //C1层map个数#define num_map_S2_CNN6 //S2层map个数#define num_map_C3_CNN16 //C3层map个数#define num_map_S4_CNN16 //S4层map个数#define num_map_C5_CNN120 //C5层map个数#define num_map_output_CNN10 //输出层map个数#define num_patterns_train_CNN60000 //训练模式对数(总数)#define num_patterns_test_CNN10000 //测试模式对数(总数)#define num_epochs_CNN100 //最大迭代次数#define accuracy_rate_CNN0.985 //要求达到的准确率#define learning_rate_CNN0.01 //学习率#define eps_CNN1e-8#define len_weight_C1_CNN150 //C1层权值数,(5*5*1)*6=150#define len_bias_C1_CNN6 //C1层阈值数,6#define len_weight_S2_CNN6 //S2层权值数,1*6=6#define len_bias_S2_CNN6 //S2层阈值数,6#define len_weight_C3_CNN2400 //C3层权值数,(5*5*6)*16=2400#define len_bias_C3_CNN16 //C3层阈值数,16#define len_weight_S4_CNN16 //S4层权值数,1*16=16#define len_bias_S4_CNN16 //S4层阈值数,16#define len_weight_C5_CNN48000 //C5层权值数,(5*5*16)*120=48000#define len_bias_C5_CNN120 //C5层阈值数,120#define len_weight_output_CNN1200 //输出层权值数,(1*120)*10=1200#define len_bias_output_CNN10 //输出层阈值数,10#define num_neuron_input_CNN1024 //输入层神经元数,(32*32)*1=1024#define num_neuron_C1_CNN4704 //C1层神经元数,(28*28)*6=4704#define num_neuron_S2_CNN1176 //S2层神经元数,(14*14)*6=1176#define num_neuron_C3_CNN1600 //C3层神经元数,(10*10)*16=1600#define num_neuron_S4_CNN400 //S4层神经元数,(5*5)*16=400#define num_neuron_C5_CNN120 //C5层神经元数,(1*1)*120=120#define num_neuron_output_CNN10 //输出层神经元数,(1*1)*10=10class CNN {public:CNN();~CNN();void init(); //初始化,分配空间protected:double E_weight_C1[len_weight_C1_CNN];double E_bias_C1[len_bias_C1_CNN];double E_weight_S2[len_weight_S2_CNN];double E_bias_S2[len_bias_S2_CNN];double E_weight_C3[len_weight_C3_CNN];double E_bias_C3[len_bias_C3_CNN];double E_weight_S4[len_weight_S4_CNN];double E_bias_S4[len_bias_S4_CNN];double* E_weight_C5;double* E_bias_C5;double* E_weight_output;double* E_bias_output;};}#endif //_CNN_HPP_
funset.cpp中的cnn1.init()定义
void CNN::init(){int len1 = width_image_input_CNN * height_image_input_CNN * num_patterns_train_CNN;//训练集输入data_input_train = new double[len1];init_variable(data_input_train, -1.0, len1);//初始化为-1int len2 = num_map_output_CNN * num_patterns_train_CNN;//训练集输出data_output_train = new double[len2];init_variable(data_output_train, -0.8, len2);//初始化-0.8int len3 = width_image_input_CNN * height_image_input_CNN * num_patterns_test_CNN;//测试集输入data_input_test = new double[len3];init_variable(data_input_test, -1.0, len3);//初始化为-1int len4 = num_map_output_CNN * num_patterns_test_CNN;//测试集输出data_output_test = new double[len4];init_variable(data_output_test, -0.8, len4);//初始化-0.8std::fill(E_weight_C1, E_weight_C1 + len_weight_C1_CNN, 0.0);//初始化0.0std::fill(E_bias_C1, E_bias_C1 + len_bias_C1_CNN, 0.0);std::fill(E_weight_S2, E_weight_S2 + len_weight_S2_CNN, 0.0);std::fill(E_bias_S2, E_bias_S2 + len_bias_S2_CNN, 0.0);std::fill(E_weight_C3, E_weight_C3 + len_weight_C3_CNN, 0.0);std::fill(E_bias_C3, E_bias_C3 + len_bias_C3_CNN, 0.0);std::fill(E_weight_S4, E_weight_S4 + len_weight_S4_CNN, 0.0);std::fill(E_bias_S4, E_bias_S4 + len_bias_S4_CNN, 0.0);E_weight_C5 = new double[len_weight_C5_CNN];std::fill(E_weight_C5, E_weight_C5 + len_weight_C5_CNN, 0.0);E_bias_C5 = new double[len_bias_C5_CNN];std::fill(E_bias_C5, E_bias_C5 + len_bias_C5_CNN, 0.0);E_weight_output = new double[len_weight_output_CNN];std::fill(E_weight_output, E_weight_output + len_weight_output_CNN, 0.0);E_bias_output = new double[len_bias_output_CNN];std::fill(E_bias_output, E_bias_output + len_bias_output_CNN, 0.0);initWeightThreshold();//初始化权重getSrcData();//载入数据}
init_variable函数定义:
void CNN::init_variable(double* val, double c, int len){//printf("%d\n", &val);for (int i = 0; i < len; i++) {val[i] = c;}}
未完待续。。。
任何问题请加唯一QQ2258205918(名称samylee)!
1 0
- CNN代码系列之训练初始化(三)
- CNN代码系列之训练源文件及头文件(二)
- CNN代码系列之数据准备(一)
- CNN训练之fine tune
- Object Detection系列(三) Fast R-CNN
- Object Detection系列(三) Fast R-CNN
- 【暑期训练三】晴天系列—G题(二分图最大匹配之匈牙利算法)
- (Caffe,LeNet)初始化训练网络(三)
- CNN训练
- 目标检测之CNN系列
- 目标检测之CNN系列
- CNN感性认识(三)——为什么深层次神经网络难于训练?
- linux中断系列之中断子系统初始化(三)
- 最小的mini2440初始化代码(三)
- MXnet代码实战之CNN
- Deep Learning模型之:CNN卷积神经网络(三)CNN常见问题总结
- 【七】Deep Learning模型之:CNN卷积神经网络(三)CNN常见问题总结
- Deep Learning模型之:CNN卷积神经网络(三)CNN常见问题总结
- Apple Catching POJ
- 消息中间件应用开发
- andoid 6.0权限下调用系统电话call
- 第13期 《We are the best!》5月刊
- 2017年山东省程序设计竞赛心得反思
- CNN代码系列之训练初始化(三)
- tar命令
- oracle 表个数
- Access子窗体递增序号自动录入
- git常用命令(一)
- react native Navigator 属性传参应用
- CSDN日报20170508 ——《面试官谈游戏入行——面试和信仰》
- Android 手写数据库框架
- 基于proteus的51单片机仿真实例五十一、基于P2口的流水灯