Esempio n. 1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            //移植元では同じ教育画像で教育しているが、より実践に近い学習に変更
            if (this.counter < 11)
            {
                //ランダムに点が打たれた画像を生成
                NdArray img_p = getRandomImage();

                //目標とするフィルタで学習用の画像を出力
                NdArray[] img_core = this.decon_core.Forward(img_p);

                //未学習のフィルタで画像を出力
                NdArray[] img_y = this.model.Forward(img_p);

                //img_yを暗黙的にNdArrayとして使用
                this.BackgroundImage = NdArrayConverter.NdArray2Image(img_y[0].GetSingleArray(0));

                Real loss = this.meanSquaredError.Evaluate(img_y, img_core);

                this.model.Backward(img_y);
                this.model.Update();

                this.Text = "[epoch" + this.counter + "] Loss : " + string.Format("{0:F4}", loss);

                this.counter++;
            }
            else
            {
                this.timer1.Enabled = false;
            }
        }
Esempio n. 2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            //At the transplant source, we are educating with the same educational image, but changing to learning closer to practice
            if (this.counter < 11)
            {
                //Generate random dotted images
                NdArray img_p = getRandomImage();

                //Output a learning image with a target filter
                NdArray[] img_core = this.decon_core.Forward(img_p);

                //Output an image with an unlearned filter
                NdArray[] img_y = this.model.Forward(img_p);

                //Implicitly use img_y as NdArray
                this.BackgroundImage = NdArrayConverter.NdArray2Image(img_y[0].GetSingleArray(0));

                Real loss = this.meanSquaredError.Evaluate(img_y, img_core);

                this.model.Backward(img_y);
                this.model.Update();

                this.Text = "[epoch" + this.counter + "] Loss : " + string.Format("{0:F4}", loss);

                this.counter++;
            }
            else
            {
                this.timer1.Enabled = false;
            }
        }
Esempio n. 3
0
        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;
            }
        }
Esempio n. 4
0
        private void button3_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog
            {
                Filter   = "pngファイル(*.png)|*.png|すべてのファイル(*.*)|*.*",
                FileName = "result.png"
            };

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                Task.Factory.StartNew(() =>
                {
                    //ネットワークへ入力する前に予め拡大しておく必要がある
                    Bitmap resultImage = new Bitmap(this._baseImage.Width * 2, this._baseImage.Height * 2, PixelFormat.Format24bppRgb);
                    Graphics g         = Graphics.FromImage(resultImage);

                    //補間にニアレストネイバーを使用
                    g.InterpolationMode = InterpolationMode.NearestNeighbor;

                    //画像を拡大して描画する
                    g.DrawImage(this._baseImage, 0, 0, this._baseImage.Width * 2, this._baseImage.Height * 2);
                    g.Dispose();

                    NdArray image         = NdArrayConverter.Image2NdArray(resultImage);
                    NdArray[] resultArray = this.nn.Predict(image);
                    resultImage           = NdArrayConverter.NdArray2Image(resultArray[0].GetSingleArray(0));
                    resultImage.Save(sfd.FileName);
                    this.pictureBox1.Image = new Bitmap(resultImage);
                }
                                      ).ContinueWith(_ =>
                {
                    MessageBox.Show("変換完了");
                });

                MessageBox.Show("変換処理は開始されました。\n『変換完了』のメッセージが表示されるまで、しばらくお待ち下さい\n※非常に時間がかかります(64x64の画像で三分ほど)");
            }
        }
Esempio n. 5
0
        private void button3_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog
            {
                Filter   = "png file (*. png) | *. png | all files (*. *) | *. *",
                FileName = "result.png"
            };

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                Task.Factory.StartNew(() =>
                {
                    //It is necessary to enlarge in advance before entering the network
                    Bitmap resultImage = new Bitmap(this._baseImage.Width * 2, this._baseImage.Height * 2, PixelFormat.Format24bppRgb);
                    Graphics g         = Graphics.FromImage(resultImage);

                    //Use nearest neighbor for interpolation
                    g.InterpolationMode = InterpolationMode.NearestNeighbor;

                    //Draw an image enlarged
                    g.DrawImage(this._baseImage, 0, 0, this._baseImage.Width * 2, this._baseImage.Height * 2);
                    g.Dispose();

                    NdArray image         = NdArrayConverter.Image2NdArray(resultImage);
                    NdArray[] resultArray = this.nn.Predict(image);
                    resultImage           = NdArrayConverter.NdArray2Image(resultArray[0].GetSingleArray(0));
                    resultImage.Save(sfd.FileName);
                    this.pictureBox1.Image = new Bitmap(resultImage);
                }
                                      ).ContinueWith(_ =>
                {
                    MessageBox.Show("Conversion complete");
                });

                MessageBox.Show("Conversion processing has been started. \n Please wait for a while until \"Conversion completed\" message is displayed \n * It will take a very long time (about three minutes with 64 x 64 images)");
            }
        }
Esempio n. 6
0
        private void button3_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog
            {
                Filter   = "png Files(*.png)|*.png|All Files(*.*)|*.*",
                FileName = "result.png"
            };

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                Task.Factory.StartNew(() =>
                {
                    // We need to enlarge in advance before entering the network
                    Bitmap resultImage = new Bitmap(_baseImage.Width * 2, _baseImage.Height * 2, PixelFormat.Format24bppRgb);
                    Graphics g         = Graphics.FromImage(resultImage);

                    // use nearest neighbor for interpolation
                    g.InterpolationMode = InterpolationMode.NearestNeighbor;

                    // Enlarge and draw the image
                    g.DrawImage(_baseImage, 0, 0, _baseImage.Width * 2, _baseImage.Height * 2);
                    g.Dispose();

                    NdArray image         = NdArrayConverter.Image2NdArray(resultImage);
                    NdArray[] resultArray = nn.Predict(true, image);
                    resultImage           = NdArrayConverter.NdArray2Image(resultArray[0].GetSingleArray(0));
                    resultImage.Save(sfd.FileName);
                    pictureBox1.Image = new Bitmap(resultImage);
                }
                                      ).ContinueWith(_ =>
                {
                    MessageBox.Show("After the exchange finished");
                });

                MessageBox.Show("The conversion process has started. \n Please wait for a while until \"conversion complete\" message is displayed \n * It will take a very long time (about 3 minutes with 64 x 64 images)");
            }
        }