Esempio n. 1
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);
        }
Esempio n. 2
0
        private void Initialize(string configurationFilename, string weightsFilename, string namesFilename, int gpu = 0, bool ignoreGpu = false, bool ignoreEnviormentReport = false)
        {
            if (IntPtr.Size != 8)
            {
                throw new NotSupportedException("Only 64-bit processes are supported");
            }

            this.EnvironmentReport = this.GetEnvironmentReport();
            this.DetectionSystem   = DetectionSystem.CPU;

            if (ignoreEnviormentReport)
            {
                if (!this.EnvironmentReport.MicrosoftVisualCPlusPlus2017RedistributableExists)
                {
                    throw new DllNotFoundException("Microsoft Visual C++ 2017-2019 Redistributable (x64)");
                }

                if (!ignoreGpu && this.EnvironmentReport.CudaExists && this.EnvironmentReport.CudnnExists)
                {
                    this.DetectionSystem = DetectionSystem.GPU;
                }
            }

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

            case DetectionSystem.GPU:
                var deviceCount = GetDeviceCount();
                if (deviceCount == 0)
                {
                    throw new NotSupportedException("No graphic device is available");
                }

                if (gpu > (deviceCount - 1))
                {
                    throw new IndexOutOfRangeException("Graphic device index is out of range");
                }

                var deviceName = new StringBuilder();     //allocate memory for string
                GetDeviceName(gpu, deviceName);
                this.EnvironmentReport.GraphicDeviceName = deviceName.ToString();

                InitializeYoloGpu(configurationFilename, weightsFilename, gpu);
                break;
            }

            this._objectTypeResolver = new YoloObjectTypeResolver(namesFilename);
        }