public void Learn(int batchcount) { foreach (var layer in Layers) { layer.Refresh(); } for (int b = 0; b < batchcount; b++) { var buf = LearningReader.GetBuffer(); //var r = new Random(); //double segvl = 0; //for (int c = 0; c < buf.Input.Channels; c++) // for (int i = 0; i < buf.Input.Width; i++) // for (int j = 0; j < buf.Input.Height; j++) // { // buf.Input.Buffer[c][i, j] = segvl; // } //buf.Input.Buffer[0][r.Next(0, buf.Input.Width / 2), r.Next(0, buf.Input.Height / 2)] = 1 - segvl; //buf.Input.Buffer[1][r.Next(0, buf.Input.Width), 0] = 1 - segvl; //buf.Input.Buffer[2][0, r.Next(0, buf.Input.Height)] = 1 - segvl; //double segvh = 0.5; //for (int c = 0; c < buf.Teacher.Channels; c++) // for (int i = 0; i < buf.Teacher.Width; i++) // for (int j = 0; j < buf.Teacher.Height; j++) // { // buf.Teacher.Buffer[c][i, j] = segvh; // } //for (int i = 0; i < 10; i++) //{ // for (int j = 0; j < 10; j++) // { // buf.Teacher.Buffer[2][3 + i, 3 - 1 + j] = 1 - segvh; // buf.Teacher.Buffer[2][3 + i, 3 + 1 + j] = 1 - segvh; // buf.Teacher.Buffer[1][0 + i, 0 + j] = 1 - segvh; // buf.Teacher.Buffer[0][3 - 1 + i, 3 + j] = 1 - segvh; // } //} InferenceProcess(buf.Input); LearnProcess(buf.Teacher); Generation++; Epoch = buf.Epoch; Teacher = buf.Teacher; } Batch++; Update(); }
public void Confirm(OpenCvSharp.Size sourceSize) { Layers[0].property.SetInputSize(sourceSize.Width, sourceSize.Height, LearningReader.ReadChannels); for (int i = 1; i < Layers.Count; i++) { Layers[i].property.SetInputSize( Layers[i - 1].property.Output.Width, Layers[i - 1].property.Output.Height, Layers[i - 1].property.Output.Channels); } for (int i = 0; i < Layers.Count - 1; i++) { Layers[i + 1].property.Input = Layers[i].property.Output; Layers[i].property.Sigma = Layers[i + 1].property.Propagater; } if (LearningReader != null) { LearningReader.ModelReflection(GPU, new Common.ModelEdgeParameter() { InputSize = new OpenCvSharp.Size(Layers[0].property.Input.Width, Layers[0].property.Input.Height), InputChannels = Layers[0].property.Input.Channels, OutputSize = new OpenCvSharp.Size(Layers[Layers.Count - 1].property.Output.Width, Layers[Layers.Count - 1].property.Output.Height), OutputChannels = Layers[Layers.Count - 1].property.Output.Channels, }); LearningReader.Start(); } if (InferenceReader != null) { InferenceReader.ModelReflection(GPU, new Common.ModelEdgeParameter() { InputSize = new OpenCvSharp.Size(Layers[0].property.Input.Width, Layers[0].property.Input.Height), InputChannels = Layers[0].property.Input.Channels, OutputSize = new OpenCvSharp.Size(Layers[Layers.Count - 1].property.Output.Width, Layers[Layers.Count - 1].property.Output.Height), OutputChannels = Layers[Layers.Count - 1].property.Output.Channels, }); InferenceReader.Start(); } }