private void Initialize(string configurationFilename, string weightsFilename, string namesFilename, int gpu = 0, bool ignoreGpu = false) { if (IntPtr.Size != 8) { throw new NotSupportedException("Only 64-bit processes are supported"); } this.EnvironmentReport = this.GetEnvironmentReport(); if (!this.EnvironmentReport.MicrosoftVisualCPlusPlus2017RedistributableExists) { throw new DllNotFoundException("Microsoft Visual C++ 2017 Redistributable (x64)"); } this.DetectionSystem = DetectionSystem.CPU; 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; } var lines = File.ReadAllLines(namesFilename); for (var i = 0; i < lines.Length; i++) { this._objectType.Add(i, lines[i]); } }
private EnvironmentReport GetEnvironmentReport() { var report = new EnvironmentReport(); report.MicrosoftVisualCPlusPlus2017RedistributableExists = this.IsMicrosoftVisualCPlusPlus2017Available(); if (File.Exists(path + @"\yoloData\x64\cudnn64_7.dll")) { report.CudnnExists = true; } var envirormentVariables = Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Machine); if (envirormentVariables.Contains("CUDA_PATH")) { report.CudaExists = true; } return(report); }