private void timer1_Tick(object sender, EventArgs e) { //移植元では同じ教育画像で教育しているが、より実践に近い学習に変更 if (counter < 11) { //ランダムに点が打たれた画像を生成 NdArray img_p = getRandomImage(); //目標とするフィルタで学習用の画像を出力 NdArray[] img_core = decon_core.Forward(img_p); //未学習のフィルタで画像を出力 NdArray[] img_y = model.Forward(img_p); //img_yを暗黙的にNdArrayとして使用 BackgroundImage = NdArrayConverter.NdArray2Image(img_y[0].GetSingleArray(0)); Real loss = meanSquaredError.Evaluate(img_y, img_core); model.Backward(img_y); model.Update(); Text = "[epoch" + counter + "] Loss : " + string.Format("{0:F4}", loss); counter++; } else { timer1.Enabled = false; } }
public static void Run() { //目標とするフィルタを作成(実践であればココは不明な値となる) Deconvolution2D decon_core = new Deconvolution2D(1, 1, 15, 1, 7, gpuEnable: true) { Weight = { Data = MakeOneCore() } }; Deconvolution2D model = new Deconvolution2D(1, 1, 15, 1, 7, gpuEnable: true); SGD optimizer = new SGD(learningRate: 0.00005); //大きいと発散する model.SetOptimizer(optimizer); MeanSquaredError meanSquaredError = new MeanSquaredError(); //移植元では同じ教育画像で教育しているが、より実践に近い学習に変更 for (int i = 0; i < 11; i++) { //ランダムに点が打たれた画像を生成 NdArray img_p = getRandomImage(); //目標とするフィルタで学習用の画像を出力 NdArray[] img_core = decon_core.Forward(img_p); //未学習のフィルタで画像を出力 NdArray[] img_y = model.Forward(img_p); Real loss = meanSquaredError.Evaluate(img_y, img_core); model.Backward(img_y); model.Update(); Console.WriteLine("epoch" + i + " : " + loss); } }
public static void Run() { // Create a target filter (In case of practice, here is the unknown value) Deconvolution2D decon_core = new Deconvolution2D(true, 1, 1, 15, 1, 7, gpuEnable: true) { Weight = { Data = MakeOneCore() } }; Deconvolution2D model = new Deconvolution2D(true, 1, 1, 15, 1, 7, gpuEnable: true); SGD optimizer = new SGD(learningRate: 0.00005); // diverge if big model.SetOptimizer(optimizer); MeanSquaredError meanSquaredError = new MeanSquaredError(); // I am educating with the same educational image at the transplanting source, but changing to learning closer to practice for (int i = 0; i < 11; i++) { // Generate an image with randomly struck points NdArray img_p = getRandomImage(); // Output a learning image with a target filter NdArray[] img_core = decon_core.Forward(true, img_p); // Output an image with an unlearned filter NdArray[] img_y = model.Forward(true, img_p); Real loss = meanSquaredError.Evaluate(img_y, img_core); model.Backward(true, img_y); model.Update(); RILogManager.Default?.SendDebug("epoch" + i + " : " + loss); } }
public static void Run() { //Create a target filter (If it is practical, here is an unknown value) Deconvolution2D decon_core = new Deconvolution2D(1, 1, 15, 1, 7, gpuEnable: true) { Weight = { Data = MakeOneCore() } }; Deconvolution2D model = new Deconvolution2D(1, 1, 15, 1, 7, gpuEnable: true); SGD optimizer = new SGD(learningRate: 0.00005); //When it is big, it diverges. model.SetOptimizer(optimizer); MeanSquaredError meanSquaredError = new MeanSquaredError(); //At the transplant source, we are educating with the same educational image, but changing to learning closer to practice for (int i = 0; i < 11; i++) { //Generate random dotted images NdArray img_p = getRandomImage(); //Output a learning image with a target filter NdArray[] img_core = decon_core.Forward(img_p); //Output an image with an unlearned filter NdArray[] img_y = model.Forward(img_p); Real loss = meanSquaredError.Evaluate(img_y, img_core); model.Backward(img_y); model.Update(); Console.WriteLine("epoch" + i + " : " + loss); } }
private void timer1_Tick(object sender, EventArgs e) { // I am educating with the same educational image at the transplanting source, but changing to learning closer to practice if (counter < 11) { // Generate an image with randomly struck points NdArray img_p = getRandomImage(); // Output a learning image with a target filter NdArray[] img_core = decon_core?.Forward(true, img_p); // Output an image with an unlearned filter NdArray[] img_y = model?.Forward(true, img_p); // implicitly use img_y as NdArray BackgroundImage = NdArrayConverter.NdArray2Image(img_y[0].GetSingleArray(0)); Real loss = meanSquaredError.Evaluate(img_y, img_core); model.Backward(true, img_y); model.Update(); Text = "[epoch" + counter + "] Loss : " + $"{loss:F4}"; counter++; } else { timer1.Enabled = false; } }