private void Form4_2_Load(object sender, EventArgs e) { cnn = new Cnn(); #region LeNet-5 结构 /* * cnn.AddCnnConvolutionLayer(6, 32, 32, 5, 5, 1, 1, CnnNode.ActivationFunctionTypes.Tanh, * 2, 2, CnnPooling.PoolingTypes.MaxPooling, false); * cnn.AddCnnConvolutionLayer(16, 5, 5, 1, 1, CnnNode.ActivationFunctionTypes.Tanh, * 2, 2, CnnPooling.PoolingTypes.MeanPooling, false, false); * cnn.AddCnnConvolutionLayer(120, 5, 5, 1, 1, CnnNode.ActivationFunctionTypes.Tanh, * 0, 0, CnnPooling.PoolingTypes.None, false, false); * cnn.AddCnnFullLayer(84, CnnNode.ActivationFunctionTypes.Tanh, false); * cnn.AddCnnFullLayer(10, CnnNode.ActivationFunctionTypes.Tanh, false); * //*/ #endregion cnn.AddCnnConvolutionLayer(6, 254 * 2, 252, 5, 5, 1, 1, CnnNode.ActivationFunctionTypes.Tanh, 2, 2, CnnPooling.PoolingTypes.MaxPooling, false); cnn.AddCnnConvolutionLayer(16, 5, 5, 1, 1, CnnNode.ActivationFunctionTypes.Tanh, 2, 2, CnnPooling.PoolingTypes.MeanPooling, false, false); cnn.AddCnnConvolutionLayer(20, 5, 5, 1, 1, CnnNode.ActivationFunctionTypes.Tanh, 2, 2, CnnPooling.PoolingTypes.MeanPooling, false, false); cnn.AddCnnFullLayer(84, CnnNode.ActivationFunctionTypes.Tanh, false); cnn.AddCnnFullLayer(1, CnnNode.ActivationFunctionTypes.Tanh, false); }
private void button2_Click(object sender, EventArgs e) { //if (args.length < 5) //{ // System.out // .println("Usage: \n\t-train trainfile\n\t-test predictfile\n\t-sep separator, default:','\n\t-eta eta, default:0.5\n\t-iter iternum, default:5000\n\t-out outputfile"); // return; //} String trainfile = @".\data\train.txt"; String testfile = @".\data\test.txt"; String outputfile = "outputfile.txt"; float eta = 0.05f; int nIter = 1000; List <CnnDemo.BP.DataNode> trainList = GetDataList(trainfile); List <CnnDemo.BP.DataNode> testList = GetDataList(testfile); StreamWriter sw = new StreamWriter(outputfile); int typeCount = 3; Cnn tmpCnn = new Cnn(); tmpCnn.AddCnnFullLayer(4, 14, CnnNode.ActivationFunctionTypes.Tanh, false); tmpCnn.AddCnnFullLayer(20, CnnNode.ActivationFunctionTypes.Tanh, false); tmpCnn.AddCnnFullLayer(10, CnnNode.ActivationFunctionTypes.Tanh, false); tmpCnn.AddCnnFullLayer(10, CnnNode.ActivationFunctionTypes.Tanh, false); tmpCnn.AddCnnFullLayer(3, CnnNode.ActivationFunctionTypes.Tanh, false); for (int i = 0; i < nIter; i++) { foreach (var t in trainList) { tmpCnn.TrainFullLayer(t.getAttribList2().ToArray(), t.getTypes(), eta); } } for (int i = 0; i < testList.Count(); i++) { CnnDemo.BP.DataNode test = testList[i]; double[] type = tmpCnn.PredictFullLayer(test.getAttribList2().ToArray()); List <float> attribs = test.getAttribList(); for (int n = 0; n < attribs.Count(); n++) { sw.Write(attribs[n] + ","); } double maxtype = type[0], max = 0; for (int n = 0; n < 3; n++) { if (maxtype < type[n]) { max = n; maxtype = type[n]; } } sw.WriteLine(GetTypeName(max)); } sw.Close(); }
private void CreateBP() { cnn = new Cnn(); cnn.AddCnnConvolutionLayer(8, bpWidth, bpHeight, 20, 20, 5, 5, CnnNode.ActivationFunctionTypes.Tanh, 2, 2, CnnPooling.PoolingTypes.MaxPooling, false); cnn.AddCnnConvolutionLayer(20, 10, 10, 3, 3, CnnNode.ActivationFunctionTypes.Tanh, 2, 2, CnnPooling.PoolingTypes.MeanPooling, false, false); cnn.AddCnnConvolutionLayer(40, 5, 5, 1, 1, CnnNode.ActivationFunctionTypes.Tanh, 2, 2, CnnPooling.PoolingTypes.MeanPooling, false, false); cnn.AddCnnConvolutionLayer(60, 5, 5, 1, 1, CnnNode.ActivationFunctionTypes.Tanh, 2, 2, CnnPooling.PoolingTypes.MeanPooling, false, false); //cnn.AddCnnConvolutionLayer(80, 5, 5, 1, 1, 1, 2, 2, 1); //cnn.AddCnnConvolutionLayer(100, 5, 5, 1, 1, 1, 2, 2, 1); cnn.AddCnnFullLayer(300, CnnNode.ActivationFunctionTypes.Tanh, false); cnn.AddCnnFullLayer(bpRectangleCount * 4, CnnNode.ActivationFunctionTypes.Tanh, false); }