示例#1
0
        public async Task Init(
            YoloVersion version = YoloVersion.YoloV3,
            System.Net.DownloadProgressChangedEventHandler onDownloadProgressChanged = null)
#endif
        {
            if (_yoloDetectionModel == null)
            {
                FileDownloadManager manager = new FileDownloadManager();

                if (version == YoloVersion.YoloV3Spp)
                {
                    manager.AddFile(
                        "https://pjreddie.com/media/files/yolov3-spp.weights",
                        _modelFolderName,
                        "87A1E8C85C763316F34E428F2295E1DB9ED4ABCEC59DD9544F8052F50DE327B4");
                    manager.AddFile(
                        "https://github.com/pjreddie/darknet/raw/master/cfg/yolov3-spp.cfg",
                        _modelFolderName,
                        "7A4EC2D7427340FB12059F2B0EF76D6FCFCAC132CC287CBBF0BE5E3ABAA856FD");
                }
                else if (version == YoloVersion.YoloV3)
                {
                    manager.AddFile(
                        "https://pjreddie.com/media/files/yolov3.weights",
                        _modelFolderName,
                        "523E4E69E1D015393A1B0A441CEF1D9C7659E3EB2D7E15F793F060A21B32F297");
                    manager.AddFile(
                        "https://github.com/pjreddie/darknet/raw/master/cfg/yolov3.cfg",
                        _modelFolderName,
                        "22489EA38575DFA36C67A90048E8759576416A79D32DC11E15D2217777B9A953");
                }
                else if (version == YoloVersion.YoloV3Tiny)
                {
                    manager.AddFile(
                        "https://pjreddie.com/media/files/yolov3-tiny.weights",
                        _modelFolderName,
                        "DCCEA06F59B781EC1234DDF8D1E94B9519A97F4245748A7D4DB75D5B7080A42C");
                    manager.AddFile(
                        "https://github.com/pjreddie/darknet/raw/master/cfg/yolov3-tiny.cfg",
                        _modelFolderName,
                        "84EB7A675EF87C906019FF5A6E0EFFE275D175ADB75100DCB47F0727917DC2C7");
                }

                manager.AddFile("https://github.com/pjreddie/darknet/raw/master/data/coco.names",
                                _modelFolderName,
                                "634A1132EB33F8091D60F2C346ABABE8B905AE08387037AED883953B7329AF84");

                if (onDownloadProgressChanged != null)
                {
                    manager.OnDownloadProgressChanged += onDownloadProgressChanged;
                }

#if (UNITY_EDITOR || UNITY_IOS || UNITY_ANDROID || UNITY_STANDALONE)
                yield return(manager.Download());
#else
                await manager.Download();
#endif

                if (manager.AllFilesDownloaded)
                {
                    _yoloDetectionModel = new DetectionModel(manager.Files[0].LocalFile, manager.Files[1].LocalFile);
                    _yoloDetectionModel.SetInputSize(new Size(416, 416));
                    _yoloDetectionModel.SetInputScale(0.00392);
                    _yoloDetectionModel.SetInputMean(new MCvScalar());

                    _labels = File.ReadAllLines(manager.Files[2].LocalFile);
                }
            }
        }
示例#2
0
文件: MaskRcnn.cs 项目: v5chn/emgucv
        public async Task Init(
            System.Net.DownloadProgressChangedEventHandler onDownloadProgressChanged = null,
            Object initOptions = null)
#endif
        {
            if (_maskRcnnDetector == null)
            {
                FileDownloadManager manager = new FileDownloadManager();

                manager.AddFile(
                    "https://github.com/emgucv/models/raw/master/mask_rcnn_inception_v2_coco_2018_01_28/frozen_inference_graph.pb",
                    _modelFolderName,
                    "AC9B51CDE227B24D20030042E6C1E29AF75668F509E51AA84ED686787CCCC309");
                manager.AddFile(
                    "https://github.com/opencv/opencv_extra/raw/4.1.0/testdata/dnn/mask_rcnn_inception_v2_coco_2018_01_28.pbtxt",
                    _modelFolderName,
                    "090923144D81B2E442093F965BE27ECCDA11CE5F781EAF1C7EC76932CE99641E");
                manager.AddFile(
                    "https://github.com/emgucv/models/raw/master/mask_rcnn_inception_v2_coco_2018_01_28/coco-labels-paper.txt",
                    _modelFolderName,
                    "8925173E1B0AABFAEFDA27DE2BB908233BB8FB6E7582323D72988E4BE15A5F0B");

                if (onDownloadProgressChanged != null)
                {
                    manager.OnDownloadProgressChanged += onDownloadProgressChanged;
                }

#if UNITY_EDITOR || UNITY_IOS || UNITY_ANDROID || UNITY_STANDALONE || UNITY_WEBGL
                yield return(manager.Download());
#else
                await manager.Download();
#endif

                if (manager.AllFilesDownloaded)
                {
                    _maskRcnnDetector = Emgu.CV.Dnn.DnnInvoke.ReadNetFromTensorflow(manager.Files[0].LocalFile, manager.Files[1].LocalFile);

                    /*
                     * _maskRcnnModel = new Model(manager.Files[0].LocalFile, manager.Files[1].LocalFile);
                     * _maskRcnnModel.SetInputSize(new Size(-1, -1));
                     * _maskRcnnModel.SetInputCrop(false);
                     * _maskRcnnModel.SetInputMean(new MCvScalar());
                     * _maskRcnnModel.SetInputSwapRB(false);
                     */

                    _labels = File.ReadAllLines(manager.Files[2].LocalFile);

                    if (initOptions != null && ((initOptions as String) != null))
                    {
                        String[] backendOptions = (initOptions as String).Split(';');
                        if (backendOptions.Length == 2)
                        {
                            String backendStr = backendOptions[0];
                            String targetStr  = backendOptions[1];

                            Dnn.Backend backend;
                            Dnn.Target  target;
                            if (Enum.TryParse(backendStr, true, out backend) &&
                                Enum.TryParse(targetStr, true, out target))
                            {
                                _maskRcnnDetector.SetPreferableBackend(backend);
                                _maskRcnnDetector.SetPreferableTarget(target);
                            }
                        }
                    }

                    if (_colors == null || _colors.Length != _labels.Length)
                    {
                        _colors = new MCvScalar[_labels.Length];
                        Random r = new Random(12345);
                        for (int i = 0; i < _colors.Length; i++)
                        {
                            _colors[i] = new MCvScalar(r.Next(256), r.Next(256), r.Next(256));
                        }
                    }
                }
            }
        }
示例#3
0
文件: Yolo.cs 项目: nurerkn/emgucv
        public async Task Init(
            YoloVersion version = YoloVersion.YoloV3,
            System.Net.DownloadProgressChangedEventHandler onDownloadProgressChanged = null)
#endif
        {
            if (_yoloDetectionModel == null)
            {
                FileDownloadManager manager = new FileDownloadManager();

                bool version3 = false;
                bool version4 = false;
                if (version == YoloVersion.YoloV3Spp)
                {
                    manager.AddFile(
                        "https://pjreddie.com/media/files/yolov3-spp.weights",
                        _modelFolderName,
                        "87A1E8C85C763316F34E428F2295E1DB9ED4ABCEC59DD9544F8052F50DE327B4");
                    manager.AddFile(
                        "https://github.com/pjreddie/darknet/raw/master/cfg/yolov3-spp.cfg",
                        _modelFolderName,
                        "7A4EC2D7427340FB12059F2B0EF76D6FCFCAC132CC287CBBF0BE5E3ABAA856FD");
                    version3 = true;
                }
                else if (version == YoloVersion.YoloV3)
                {
                    manager.AddFile(
                        "https://pjreddie.com/media/files/yolov3.weights",
                        _modelFolderName,
                        "523E4E69E1D015393A1B0A441CEF1D9C7659E3EB2D7E15F793F060A21B32F297");
                    manager.AddFile(
                        "https://github.com/pjreddie/darknet/raw/master/cfg/yolov3.cfg",
                        _modelFolderName,
                        "22489EA38575DFA36C67A90048E8759576416A79D32DC11E15D2217777B9A953");
                    version3 = true;
                }
                else if (version == YoloVersion.YoloV3Tiny)
                {
                    manager.AddFile(
                        "https://pjreddie.com/media/files/yolov3-tiny.weights",
                        _modelFolderName,
                        "DCCEA06F59B781EC1234DDF8D1E94B9519A97F4245748A7D4DB75D5B7080A42C");
                    manager.AddFile(
                        "https://github.com/pjreddie/darknet/raw/master/cfg/yolov3-tiny.cfg",
                        _modelFolderName,
                        "84EB7A675EF87C906019FF5A6E0EFFE275D175ADB75100DCB47F0727917DC2C7");
                    version3 = true;
                }
                else if (version == YoloVersion.YoloV4)
                {
                    manager.AddFile(
                        "https://github.com/aj-ames/YOLOv4-OpenCV-CUDA-DNN/raw/dd58dba457fff98e483e0f67113e0be1f17f2120/models/yolov4.weights",
                        _modelFolderName,
                        "8463FDE6EE7130A947A73104CE73C6FA88618A9D9ECD4A65D0B38F07E17EC4E4");
                    manager.AddFile(
                        "https://github.com/aj-ames/YOLOv4-OpenCV-CUDA-DNN/raw/dd58dba457fff98e483e0f67113e0be1f17f2120/models/yolov4.cfg",
                        _modelFolderName,
                        "A15524EC710005ADD4EB672140CF15CBFE46DEA0561F1AEA90CB1140B466073E");
                    version4 = true;
                }
                else if (version == YoloVersion.YoloV4Tiny)
                {
                    manager.AddFile(
                        "https://github.com/aj-ames/YOLOv4-OpenCV-CUDA-DNN/raw/dd58dba457fff98e483e0f67113e0be1f17f2120/models/yolov4-tiny.weights",
                        _modelFolderName,
                        "CF9FBFD0F6D4869B35762F56100F50ED05268084078805F0E7989EFE5BB8CA87");
                    manager.AddFile(
                        "https://github.com/aj-ames/YOLOv4-OpenCV-CUDA-DNN/raw/dd58dba457fff98e483e0f67113e0be1f17f2120/models/yolov4-tiny.cfg",
                        _modelFolderName,
                        "6CBF5ECE15235F66112E0BEDEBB324F37199B31AEE385B7E18F0BBFB536B258E");
                    version4 = true;
                }

                if (version3)
                {
                    manager.AddFile("https://github.com/pjreddie/darknet/raw/master/data/coco.names",
                                    _modelFolderName,
                                    "634A1132EB33F8091D60F2C346ABABE8B905AE08387037AED883953B7329AF84");
                }
                if (version4)
                {
                    manager.AddFile("https://github.com/aj-ames/YOLOv4-OpenCV-CUDA-DNN/raw/dd58dba457fff98e483e0f67113e0be1f17f2120/models/coco.names",
                                    _modelFolderName,
                                    "634A1132EB33F8091D60F2C346ABABE8B905AE08387037AED883953B7329AF84");
                }

                if (onDownloadProgressChanged != null)
                {
                    manager.OnDownloadProgressChanged += onDownloadProgressChanged;
                }

#if UNITY_EDITOR || UNITY_IOS || UNITY_ANDROID || UNITY_STANDALONE || UNITY_WEBGL
                yield return(manager.Download());
#else
                await manager.Download();
#endif

                if (manager.AllFilesDownloaded)
                {
                    _yoloDetectionModel = new DetectionModel(manager.Files[0].LocalFile, manager.Files[1].LocalFile);
                    _yoloDetectionModel.SetInputSize(new Size(416, 416));
                    _yoloDetectionModel.SetInputScale(0.00392);
                    _yoloDetectionModel.SetInputMean(new MCvScalar());

                    _labels = File.ReadAllLines(manager.Files[2].LocalFile);
                }
            }
        }
示例#4
0
文件: Resnet.cs 项目: emgucv/emgutf
        Init(
            DownloadableFile modelFile = null,
            DownloadableFile labelFile = null,
            String inputName           = null,
            String outputName          = null
            )
        {
            if (_session == null)
            {
                _inputName  = inputName == null ? "serving_default_input_1" : inputName;
                _outputName = outputName == null ? "StatefulPartitionedCall" : outputName;

                _downloadManager.Clear();

                String defaultLocalSubfolder = "Resnet";
                if (modelFile == null)
                {
                    modelFile = new DownloadableFile(
                        "https://github.com/emgucv/models/raw/master/resnet/resnet_50_classification_1.zip",
                        defaultLocalSubfolder,
                        "861BA3BA5F18D8985A5611E5B668A0A020998762DD5A932BD4D0BCBBC1823A83"
                        );
                }

                if (labelFile == null)
                {
                    labelFile = new DownloadableFile(
                        "https://github.com/emgucv/models/raw/master/resnet/ImageNetLabels.txt",
                        defaultLocalSubfolder,
                        "536FEACC519DE3D418DE26B2EFFB4D75694A8C4C0063E36499A46FA8061E2DA9"
                        );
                }

                _downloadManager.AddFile(modelFile);
                _downloadManager.AddFile(labelFile);

#if UNITY_EDITOR || UNITY_IOS || UNITY_ANDROID || UNITY_STANDALONE
                yield return(_downloadManager.Download());
#else
                await _downloadManager.Download();
#endif
                if (_downloadManager.AllFilesDownloaded)
                {
                    System.IO.FileInfo localZipFile = new System.IO.FileInfo(_downloadManager.Files[0].LocalFile);

                    _savedModelDir = System.IO.Path.Combine(localZipFile.DirectoryName, "SavedModel");
                    if (!System.IO.Directory.Exists(_savedModelDir))
                    {
                        System.IO.Directory.CreateDirectory(_savedModelDir);

                        System.IO.Compression.ZipFile.ExtractToDirectory(
                            localZipFile.FullName,
                            _savedModelDir);
                    }

                    CreateSession();
                }
                else
                {
                    System.Diagnostics.Trace.WriteLine("Failed to download files");
                }
            }
        }