差分
このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
| opencv_dnn:環境構築:dnn_with_cuda [2020/02/12 18:04] – baba | opencv_dnn:環境構築:dnn_with_cuda [2020/02/23 14:51] (現在) – [OpenCV DNN with CUDA] baba | ||
|---|---|---|---|
| 行 2: | 行 2: | ||
| このページでは,OpenCVのdnnモジュールをcudaでinferenceさせるための環境構築に関してまとめます.もともとの動機は | このページでは,OpenCVのdnnモジュールをcudaでinferenceさせるための環境構築に関してまとめます.もともとの動機は | ||
| * OpenCVのdnn inferenceをもっと早くしたい | * OpenCVのdnn inferenceをもっと早くしたい | ||
| - | なわけです.もちろんintelのinference engine ( https:// | + | なわけです.もちろんintelのinference engine ( https:// |
| 参考にした記事は以下となります.日本語でこのあたりをubuntu環境でやってる人がいなかったのでここに記しておくことにしました. | 参考にした記事は以下となります.日本語でこのあたりをubuntu環境でやってる人がいなかったのでここに記しておくことにしました. | ||
| 行 17: | 行 17: | ||
| * cuDNN 7.6.4 | * cuDNN 7.6.4 | ||
| - | cmakeでconfigureする際に,導入しているバージョンが複数ある場合は,適切なバージョンに変更するなどのマニュアル作業が生じます.例えばcuda10.2でやり | + | cmakeでconfigureする際に,導入しているバージョンが複数ある場合は,適切なバージョンに変更するなどのマニュアル作業が生じます.できればcmake-guiを利用してパスやバージョンが正しいかを細かく確認することをおすすめします.特にmakeに難しいことはないですが,エラーが出る場合はcuda周りを一通りチェックしてください.また,opencv_contribが必要なのでそれも忘れずに.必要に応じてnvidia-dockerすると良いかなと思います. |
| ==== object_detection.cppの修正 ==== | ==== object_detection.cppの修正 ==== | ||
| 行 367: | 行 367: | ||
| std:: | std:: | ||
| std:: | std:: | ||
| - | if (outLayerType == " | + | boxes.clear(); |
| + | | ||
| + | { | ||
| + | /* | ||
| + | // Network produces output blob with a shape 1x1xNx7 where N is a number of | ||
| + | // detections and an every detection is a vector of values | ||
| + | // [batchId, classId, confidence, left, top, right, bottom] | ||
| + | CV_Assert(outs.size() == 1); | ||
| + | float* data = (float*)outs[0].data; | ||
| + | for (size_t i = 0; i < outs[0].total(); | ||
| + | { | ||
| + | float confidence = data[i + 2]; | ||
| + | if (confidence > confidenceThreshold) | ||
| + | { | ||
| + | int left = (int)data[i + 3]; | ||
| + | int top = (int)data[i + 4]; | ||
| + | int right = (int)data[i + 5]; | ||
| + | int bottom = (int)data[i + 6]; | ||
| + | int width = right - left + 1; | ||
| + | int height = bottom - top + 1; | ||
| + | classIds.push_back((int)(data[i + 1]) - 1); // Skip 0th background class id. | ||
| + | // boxes.push_back(Rect(left, | ||
| + | confidences.push_back(confidence); | ||
| + | } | ||
| + | } | ||
| + | */ | ||
| + | } | ||
| + | else if (outLayerType == " | ||
| { | { | ||
| // Network produces output blob with a shape 1x1xNx7 where N is a number of | // Network produces output blob with a shape 1x1xNx7 where N is a number of | ||
| 行 435: | 行 462: | ||
| else | else | ||
| CV_Error(Error:: | CV_Error(Error:: | ||
| + | |||
| std:: | std:: | ||
| 行 445: | 行 473: | ||
| box.x + box.width, box.y + box.height, frame); | box.x + box.width, box.y + box.height, frame); | ||
| } | } | ||
| + | |||
| + | |||
| } | } | ||