private const float nmsThreshold = 0.3f; //threshold for nms public YoloBatchedDnnDetector(ILogger <YoloBatchedDnnDetector> logger, IOptions <Yolo3Options> yoloOptions, IOptions <VideoStreamsOptions> streamOptions) : base(logger, yoloOptions) { _roiConfig = GetValidatedOptions <VideoStreamsOptions>(streamOptions). ToDictionary(o => o.Id, o => o.ROI); //YOLOv3 File locations //Cfg: https://github.com/pjreddie/darknet/blob/master/cfg/yolov3.cfg //Weight: https://pjreddie.com/media/files/yolov3.weights //Names: https://github.com/pjreddie/darknet/blob/master/data/coco.names var cfg = Path.Combine(Options.RootPath, Options.ConfigFile); var weight = Path.Combine(Options.RootPath, Options.WeightsFile); var names = Path.Combine(Options.RootPath, Options.NamesFile); //random assign color to each label Labels = File.ReadAllLines(names).ToArray(); //get labels from coco.names Colors = Enumerable.Repeat(false, Labels.Length).Select(x => Scalar.RandomColor()).ToArray(); Logger.LogInformation("Loading Neural Net"); //Does not result in a null object, but will trow exception on errors, so safe to assume non-null nnet = OpenCvSharp.Dnn.CvDnn.ReadNetFromDarknet(cfg, weight) !; _outNames = nnet.GetUnconnectedOutLayersNames() !; outs = Enumerable.Repeat(false, _outNames.Length).Select(_ => new Mat()).ToArray(); }
public Yolo2DnnDetector(ILogger <IDnnDetector> logger) { _logger = logger; nnet = OpenCvSharp.Dnn.CvDnn.ReadNetFromDarknet(Cfg, Weight); //nnet.SetPreferableBackend(Net.Backend.INFERENCE_ENGINE); //nnet.SetPreferableTarget(Net.Target.CPU); _outNames = nnet.GetUnconnectedOutLayersNames() !; }
public Yolo3BatchedDnnDetector(ILogger <IDnnDetector> logger, IConfiguration configuration) { if (configuration is null) { throw new ArgumentNullException(nameof(configuration)); } if (logger is null) { throw new ArgumentNullException(nameof(logger)); } _logger = logger; var options = new Yolo3Options(); configuration.GetSection(Yolo3Options.Yolo3).Bind(options); Cfg = Path.Combine(options.RootPath, options.ConfigFile); Weight = Path.Combine(options.RootPath, options.WeightsFile); Names = Path.Combine(options.RootPath, options.NamesFile); //random assign color to each label Labels = File.ReadAllLines(Names).ToArray(); //get labels from coco.names Colors = Enumerable.Repeat(false, Labels.Length).Select(x => Scalar.RandomColor()).ToArray(); _logger.LogInformation("Loading Neural Net"); nnet = OpenCvSharp.Dnn.CvDnn.ReadNetFromDarknet(Cfg, Weight); //nnet.SetPreferableBackend(Net.Backend.INFERENCE_ENGINE); //nnet.SetPreferableTarget(Net.Target.OPENCL); _outNames = nnet.GetUnconnectedOutLayersNames() !; outs = Enumerable.Repeat(false, _outNames.Length).Select(_ => new Mat()).ToArray(); _logger.LogInformation("Warm Up Neural Net with Dummy images"); //Initialize(); }