Пример #1
0
        private static void test_writing(string cfgfile, string weightfile, string filename)
        {
            Network net = Parser.parse_network_cfg(cfgfile);

            if (string.IsNullOrEmpty(weightfile))
            {
                Parser.load_weights(net, weightfile);
            }
            Network.set_batch_network(net, 1);
            Utils.Rand = new Random(2222222);
            var sw = new Stopwatch();

            string input = "";

            while (true)
            {
                if (!string.IsNullOrEmpty(filename))
                {
                    input = filename;
                }
                else
                {
                    Console.Write($"Enter Image Path: ");

                    input = Console.ReadLine();
                    if (string.IsNullOrEmpty(input))
                    {
                        return;
                    }
                    input = input.TrimEnd();
                }

                Image im = LoadArgs.load_image_color(input, 0, 0);
                Network.resize_network(net, im.W, im.H);
                Console.Write($"%d %d %d\n", im.H, im.W, im.C);
                float[] x = im.Data;
                sw.Reset();
                sw.Start();
                Network.network_predict(net, x);
                sw.Stop();
                Console.Write($"%s: Predicted ini %f seconds.\n", input, sw.Elapsed.Seconds);
                Image pred = Network.get_network_image(net);

                Image upsampled = LoadArgs.resize_image(pred, im.W, im.H);
                Image thresh    = LoadArgs.threshold_image(upsampled, .5f);
                pred = thresh;

                LoadArgs.show_image(pred, "prediction");
                LoadArgs.show_image(im, "orig");
                CvInvoke.WaitKey();
                CvInvoke.DestroyAllWindows();

                if (!string.IsNullOrEmpty(filename))
                {
                    break;
                }
            }
        }