예제 #1
0
파일: YoloWrapper.cs 프로젝트: csuffyy/Igor
        /// <summary>
        /// Initialize Yolo
        /// </summary>
        /// <param name="yoloConfiguration"></param>
        /// <param name="ignoreGpu">Disable automatic gpu detection</param>
        /// <exception cref="NotSupportedException">Thrown when the process not run in 64bit</exception>
        /// <exception cref="YoloInitializeException">Thrown if an error occurs during initialization</exception>
        public YoloWrapper(YoloConfiguration yoloConfiguration, GpuConfig gpuConfig = null, IYoloSystemValidator yoloSystemValidator = null)
        {
            if (yoloSystemValidator == null)
            {
                this._yoloSystemValidator = new DefaultYoloSystemValidator();
            }

            this.Initialize(yoloConfiguration.ConfigFile, yoloConfiguration.WeightsFile, yoloConfiguration.NamesFile, gpuConfig);
        }
예제 #2
0
        public string GetGraphicDeviceName(GpuConfig gpuConfig)
        {
            if (gpuConfig == null)
            {
                return(string.Empty);
            }

            var systemReport = this._yoloSystemValidator.Validate();

            if (!systemReport.CudaExists || !systemReport.CudnnExists)
            {
                return("unknown");
            }

            var deviceName = new StringBuilder(); //allocate memory for string

            GetDeviceName(gpuConfig.GpuIndex, deviceName);
            return(deviceName.ToString());
        }
예제 #3
0
        /// <summary>
        /// Initialize Yolo
        /// </summary>
        /// <param name="configurationFilename">Yolo configuration (.cfg) file path</param>
        /// <param name="weightsFilename">Yolo trainded data (.weights) file path</param>
        /// <param name="namesFilename">Yolo object names (.names) file path</param>
        /// <param name="gpu">Gpu Index if multiple graphic devices available</param>
        /// <param name="ignoreGpu">Disable automatic gpu detection</param>
        /// <exception cref="NotSupportedException">Thrown when the process not run in 64bit</exception>
        /// <exception cref="YoloInitializeException">Thrown if an error occurs during initialization</exception>
        public YoloWrapper(string configurationFilename, string weightsFilename, string namesFilename, GpuConfig gpuConfig = null, IYoloSystemValidator yoloSystemValidator = null)
        {
            if (yoloSystemValidator == null)
            {
                this._yoloSystemValidator = new DefaultYoloSystemValidator();
            }
            else
            {
                this._yoloSystemValidator = yoloSystemValidator;
            }

            this.Initialize(configurationFilename, weightsFilename, namesFilename, gpuConfig);
        }
예제 #4
0
        private void Initialize(string configurationFilename, string weightsFilename, string namesFilename, GpuConfig gpuConfig)
        {
            if (IntPtr.Size != 8)
            {
                throw new NotSupportedException("Only 64-bit processes are supported");
            }

            var systemReport = this._yoloSystemValidator.Validate();

            if (!systemReport.MicrosoftVisualCPlusPlusRedistributableExists)
            {
                throw new YoloInitializeException("Microsoft Visual C++ 2017-2019 Redistributable (x64)");
            }

            this.DetectionSystem = DetectionSystem.CPU;

            if (gpuConfig != null)
            {
                if (!systemReport.CudaExists)
                {
                    throw new YoloInitializeException("Cuda files not found");
                }

                if (!systemReport.CudnnExists)
                {
                    throw new YoloInitializeException("Cudnn not found");
                }

                var deviceCount = GetDeviceCount();
                if (deviceCount == 0)
                {
                    throw new YoloInitializeException("No Nvidia graphic device is available");
                }

                if (gpuConfig.GpuIndex > (deviceCount - 1))
                {
                    throw new YoloInitializeException("Graphic device index is out of range");
                }

                this.DetectionSystem = DetectionSystem.GPU;
            }

            switch (this.DetectionSystem)
            {
            case DetectionSystem.CPU:
                InitializeYoloCpu(configurationFilename, weightsFilename, 0);
                break;

            case DetectionSystem.GPU:
                InitializeYoloGpu(configurationFilename, weightsFilename, gpuConfig.GpuIndex);
                break;
            }

            this._objectTypeResolver = new YoloObjectTypeResolver(namesFilename);
        }