Пример #1
0
        private static void test_coco(string cfgfile, string weightfile, string filename, float thresh)
        {
            Image[][] alphabet = LoadArgs.load_alphabet();
            Network net = Parser.parse_network_cfg(cfgfile);
            if (string.IsNullOrEmpty(weightfile))
            {
                Parser.load_weights(net, weightfile);
            }
            Layer l = net.Layers[net.N - 1];
            Network.set_batch_network(net, 1);
            Utils.Rand = new Random(2222222);
            float nms = .4f;
            var sw = new Stopwatch();

            int j;
            Box[] boxes = new Box[l.Side * l.Side * l.N];
            float[][] probs = new float[l.Side * l.Side * l.N][];
            for (j = 0; j < l.Side * l.Side * l.N; ++j) probs[j] = new float[l.Classes];
            while (true)
            {
                string input;
                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);
                Image sized = LoadArgs.resize_image(im, net.W, net.H);
                float[] x = sized.Data;
                sw.Reset();
                sw.Start();
                Network.network_predict(net, x);
                sw.Stop();
                Console.Write($"%s: Predicted ini %f seconds.\n", input, sw.Elapsed.Seconds);
                l.get_detection_boxes( 1, 1, thresh, probs, boxes, false);
                if (nms != 0) Box.do_nms_sort(boxes, probs, l.Side * l.Side * l.N, l.Classes, nms);
                LoadArgs.draw_detections(im, l.Side * l.Side * l.N, thresh, boxes, probs, CocoClasses, alphabet, 80);
                LoadArgs.save_image(im, "prediction");
                LoadArgs.show_image(im, "predictions");
                CvInvoke.WaitKey();
                CvInvoke.DestroyAllWindows();
                if (!string.IsNullOrEmpty(filename)) break;
            }
        }
Пример #2
0
        private static void detect_in_thread()
        {
            float nms = .4f;

            Layer l = net.Layers[net.N - 1];

            float[] x          = detS.Data;
            float[] prediction = Network.network_predict(net, x);

            Array.Copy(prediction, 0, prediction, demoIndex, l.Outputs);
            Utils.mean_arrays(predictions, frames, l.Outputs, avg);
            l.Output = avg;

            if (l.LayerType == LayerType.Detection)
            {
                l.get_detection_boxes(1, 1, demoThresh, probs, boxes, false);
            }
            else if (l.LayerType == LayerType.Region)
            {
                Layer.get_region_boxes(l, 1, 1, demoThresh, probs, boxes, false, new int[0]);
            }
            else
            {
                Utils.Error("Last Layer must produce detections\n");
            }
            if (nms > 0)
            {
                Box.do_nms(boxes, probs, l.W * l.H * l.N, l.Classes, nms);
            }
            Console.Write($"\033[2J");
            Console.Write($"\033[1;1H");
            Console.Write($"\nFPS:%.1f\n", fps);
            Console.Write($"Objects:\n\n");

            images[demoIndex] = det;
            det       = images[(demoIndex + frames / 2 + 1) % frames];
            demoIndex = (demoIndex + 1) % frames;

            LoadArgs.draw_detections(det, l.W * l.H * l.N, demoThresh, boxes, probs, demoNames, demoAlphabet, demoClasses);
        }
Пример #3
0
        public static void test_detector(string datacfg, string cfgfile, string weightfile, string filename, float thresh)
        {
            var    options  = OptionList.read_data_cfg(datacfg);
            string nameList = OptionList.option_find_str(options, "names", "Data.Data/names.list");

            string[] names = Data.Data.get_labels(nameList);

            Image[][] alphabet = LoadArgs.load_alphabet();
            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 = "";
            int    j;
            float  nms = .4f;

            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);
                Image sized = LoadArgs.resize_image(im, net.W, net.H);
                Layer l     = net.Layers[net.N - 1];

                Box[]     boxes = new Box[l.W * l.H * l.N];
                float[][] probs = new float[l.W * l.H * l.N][];
                for (j = 0; j < l.W * l.H * l.N; ++j)
                {
                    probs[j] = new float[l.Classes];
                }

                float[] x = sized.Data;
                sw.Start();
                Network.network_predict(net, x);
                sw.Stop();
                Console.Write($"%s: Predicted ini %f seconds.\n", input, sw.Elapsed.Seconds);
                Layer.get_region_boxes(l, 1, 1, thresh, probs, boxes, false, new int[0]);
                if (nms != 0)
                {
                    Box.do_nms_sort(boxes, probs, l.W * l.H * l.N, l.Classes, nms);
                }
                LoadArgs.draw_detections(im, l.W * l.H * l.N, thresh, boxes, probs, names, alphabet, l.Classes);
                LoadArgs.save_image(im, "predictions");
                LoadArgs.show_image(im, "predictions");

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