尽管指定使用 GPU,YOLO 仍继续使用 CPU
YOLO keep using CPU despite of specifying using GPU
我使用的笔记本电脑配备 GPU 0:Intel(R) HD Graphics 630 和 GPU 1:GTX1050 TI。我刚刚使用以下教程在 Anaconda 环境中设置了 YOLO 环境:https://appliedmachinelearning.blog/2018/05/27/running-yolo-v2-for-real-time-object-detection-on-videos-images-via-darkflow/
问题是:每当我尝试使用 GPU 在 Anaconda 环境中使用 YOLO 渲染视频时
python flow --model cfg/yolo.cfg --load bin/yolov2.weights --demo videofile.mp4 --saveVideo --gpu 0.5
视频确实成功渲染,但是,我的 CPU 使用率上升到几乎 100%(任务管理器),而我的 GPU 根本没有使用。我尝试通过在末尾添加 --gpuName /gpu:1 来指定 GPU 名称,但仍然使用了 CPU。这是从 Anaconda Prompt 复制的输出行。
(df) C:\Users\User\Videos\PC-programming\darkflow-master>python flow --model cfg/yolo.cfg --load bin/yolov2.weights --demo videofile.mp4 --saveVideo --gpu 0.5
Parsing ./cfg/yolov2.cfg
Parsing cfg/yolo.cfg
Loading bin/yolov2.weights ...
Successfully identified 203934260 bytes
Finished in 0.022666454315185547s
Model has a coco model name, loading coco labels.
Building net ...
Source | Train? | Layer description | Output size
-------+--------+----------------------------------+---------------
| | input | (?, 608, 608, 3)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 608, 608, 32)
Load | Yep! | maxp 2x2p0_2 | (?, 304, 304, 32)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 304, 304, 64)
Load | Yep! | maxp 2x2p0_2 | (?, 152, 152, 64)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 152, 152, 128)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 152, 152, 64)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 152, 152, 128)
Load | Yep! | maxp 2x2p0_2 | (?, 76, 76, 128)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 76, 76, 256)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 76, 76, 128)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 76, 76, 256)
Load | Yep! | maxp 2x2p0_2 | (?, 38, 38, 256)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 38, 38, 512)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 38, 38, 256)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 38, 38, 512)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 38, 38, 256)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 38, 38, 512)
Load | Yep! | maxp 2x2p0_2 | (?, 19, 19, 512)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 19, 19, 512)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 19, 19, 512)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | concat [16] | (?, 38, 38, 512)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 38, 38, 64)
Load | Yep! | local flatten 2x2 | (?, 19, 19, 256)
Load | Yep! | concat [27, 24] | (?, 19, 19, 1280)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 1x1p0_1 linear | (?, 19, 19, 425)
-------+--------+----------------------------------+---------------
GPU mode with 0.5 usage
2018-10-16 17:21:18.897583: W C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2018-10-16 17:21:18.904824: W C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
Finished in 4.7458178997039795s
Press [ESC] to quit demo
0.719 FPS ......
然后,如果我尝试渲染图像,任务管理器仍然显示根本没有使用 GPU。
(df) C:\Users\User\Videos\PC-programming\darkflow-master>python flow --model cfg/yolo.cfg --load bin/yolov2.weights --imgdir sample_img --gpu 0.9
Parsing ./cfg/yolov2.cfg
Parsing cfg/yolo.cfg
Loading bin/yolov2.weights ...
Successfully identified 203934260 bytes
Finished in 0.021943330764770508s
Model has a coco model name, loading coco labels.
Building net ...
Source | Train? | Layer description | Output size
-------+--------+----------------------------------+---------------
| | input | (?, 608, 608, 3)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 608, 608, 32)
Load | Yep! | maxp 2x2p0_2 | (?, 304, 304, 32)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 304, 304, 64)
Load | Yep! | maxp 2x2p0_2 | (?, 152, 152, 64)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 152, 152, 128)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 152, 152, 64)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 152, 152, 128)
Load | Yep! | maxp 2x2p0_2 | (?, 76, 76, 128)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 76, 76, 256)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 76, 76, 128)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 76, 76, 256)
Load | Yep! | maxp 2x2p0_2 | (?, 38, 38, 256)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 38, 38, 512)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 38, 38, 256)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 38, 38, 512)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 38, 38, 256)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 38, 38, 512)
Load | Yep! | maxp 2x2p0_2 | (?, 19, 19, 512)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 19, 19, 512)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 19, 19, 512)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | concat [16] | (?, 38, 38, 512)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 38, 38, 64)
Load | Yep! | local flatten 2x2 | (?, 19, 19, 256)
Load | Yep! | concat [27, 24] | (?, 19, 19, 1280)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 1x1p0_1 linear | (?, 19, 19, 425)
-------+--------+----------------------------------+---------------
GPU mode with 0.9 usage
2018-10-16 17:07:30.439641: W C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2018-10-16 17:07:30.449381: W C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
Finished in 5.261923789978027s
Forwarding 8 inputs ...
Total time = 10.975605964660645s / 8 inps = 0.7288891406778334 ips
Post processing 8 inputs ...
Total time = 0.48075294494628906s / 8 inps = 16.640563690969756 ips
怎么了 >_< ???提前致谢!
您是否对 Makefile 进行了一些更改,在 Makefile 中启用了 GPU 和 CUDNN。注意路径。
克隆 https://github.com/thtrieu/darkflow,
从 https://pjreddie.com/darknet/yolo/、
下载必要的 .cfg 和权重
将它们分别保存在 darkflow-master 中的 cfg 文件夹和一个新的 bin 文件夹中。
conda create -n darkflow-env python=3.6
activate darkflow-env
pip install tensorflow-gpu
(pip,不是conda。这一步应该也会自动安装CUDA和cuDNN,不需要单独下载。)
conda install cython numpy
conda config --add channels conda-forge
conda install opencv
转到您的 darkflow-master 文件夹并复制路径
cd 到路径(仍然使用 Anaconda Prompt)
python setup.py build_ext --inplace
python flow --model cfg/yolo.cfg --load bin/yolov2.weights --demo videofile.mp4 --saveVideo --gpu 0.7
(videofile.mp4是要渲染的视频,我直接放在darkflow-master文件夹下)
稍等一下,您会在 darkflow-master 文件夹中看到输出视频(在我的 GTX1050 TI 显卡笔记本电脑上,渲染速度约为 8.5 FPS)。
如果遇到需要Microsoft Visual C++ Build Tools之类的问题,那么只需从Microsoft网站下载,记得在安装的同时安装SDK。有关此问题的更多信息,您可以参考 https://github.com/thtrieu/darkflow/issues/788。
我使用的笔记本电脑配备 GPU 0:Intel(R) HD Graphics 630 和 GPU 1:GTX1050 TI。我刚刚使用以下教程在 Anaconda 环境中设置了 YOLO 环境:https://appliedmachinelearning.blog/2018/05/27/running-yolo-v2-for-real-time-object-detection-on-videos-images-via-darkflow/
问题是:每当我尝试使用 GPU 在 Anaconda 环境中使用 YOLO 渲染视频时
python flow --model cfg/yolo.cfg --load bin/yolov2.weights --demo videofile.mp4 --saveVideo --gpu 0.5
视频确实成功渲染,但是,我的 CPU 使用率上升到几乎 100%(任务管理器),而我的 GPU 根本没有使用。我尝试通过在末尾添加 --gpuName /gpu:1 来指定 GPU 名称,但仍然使用了 CPU。这是从 Anaconda Prompt 复制的输出行。
(df) C:\Users\User\Videos\PC-programming\darkflow-master>python flow --model cfg/yolo.cfg --load bin/yolov2.weights --demo videofile.mp4 --saveVideo --gpu 0.5
Parsing ./cfg/yolov2.cfg
Parsing cfg/yolo.cfg
Loading bin/yolov2.weights ...
Successfully identified 203934260 bytes
Finished in 0.022666454315185547s
Model has a coco model name, loading coco labels.
Building net ...
Source | Train? | Layer description | Output size
-------+--------+----------------------------------+---------------
| | input | (?, 608, 608, 3)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 608, 608, 32)
Load | Yep! | maxp 2x2p0_2 | (?, 304, 304, 32)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 304, 304, 64)
Load | Yep! | maxp 2x2p0_2 | (?, 152, 152, 64)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 152, 152, 128)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 152, 152, 64)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 152, 152, 128)
Load | Yep! | maxp 2x2p0_2 | (?, 76, 76, 128)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 76, 76, 256)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 76, 76, 128)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 76, 76, 256)
Load | Yep! | maxp 2x2p0_2 | (?, 38, 38, 256)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 38, 38, 512)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 38, 38, 256)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 38, 38, 512)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 38, 38, 256)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 38, 38, 512)
Load | Yep! | maxp 2x2p0_2 | (?, 19, 19, 512)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 19, 19, 512)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 19, 19, 512)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | concat [16] | (?, 38, 38, 512)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 38, 38, 64)
Load | Yep! | local flatten 2x2 | (?, 19, 19, 256)
Load | Yep! | concat [27, 24] | (?, 19, 19, 1280)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 1x1p0_1 linear | (?, 19, 19, 425)
-------+--------+----------------------------------+---------------
GPU mode with 0.5 usage
2018-10-16 17:21:18.897583: W C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2018-10-16 17:21:18.904824: W C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
Finished in 4.7458178997039795s
Press [ESC] to quit demo
0.719 FPS ......
然后,如果我尝试渲染图像,任务管理器仍然显示根本没有使用 GPU。
(df) C:\Users\User\Videos\PC-programming\darkflow-master>python flow --model cfg/yolo.cfg --load bin/yolov2.weights --imgdir sample_img --gpu 0.9
Parsing ./cfg/yolov2.cfg
Parsing cfg/yolo.cfg
Loading bin/yolov2.weights ...
Successfully identified 203934260 bytes
Finished in 0.021943330764770508s
Model has a coco model name, loading coco labels.
Building net ...
Source | Train? | Layer description | Output size
-------+--------+----------------------------------+---------------
| | input | (?, 608, 608, 3)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 608, 608, 32)
Load | Yep! | maxp 2x2p0_2 | (?, 304, 304, 32)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 304, 304, 64)
Load | Yep! | maxp 2x2p0_2 | (?, 152, 152, 64)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 152, 152, 128)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 152, 152, 64)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 152, 152, 128)
Load | Yep! | maxp 2x2p0_2 | (?, 76, 76, 128)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 76, 76, 256)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 76, 76, 128)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 76, 76, 256)
Load | Yep! | maxp 2x2p0_2 | (?, 38, 38, 256)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 38, 38, 512)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 38, 38, 256)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 38, 38, 512)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 38, 38, 256)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 38, 38, 512)
Load | Yep! | maxp 2x2p0_2 | (?, 19, 19, 512)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 19, 19, 512)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 19, 19, 512)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | concat [16] | (?, 38, 38, 512)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 38, 38, 64)
Load | Yep! | local flatten 2x2 | (?, 19, 19, 256)
Load | Yep! | concat [27, 24] | (?, 19, 19, 1280)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 1x1p0_1 linear | (?, 19, 19, 425)
-------+--------+----------------------------------+---------------
GPU mode with 0.9 usage
2018-10-16 17:07:30.439641: W C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2018-10-16 17:07:30.449381: W C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
Finished in 5.261923789978027s
Forwarding 8 inputs ...
Total time = 10.975605964660645s / 8 inps = 0.7288891406778334 ips
Post processing 8 inputs ...
Total time = 0.48075294494628906s / 8 inps = 16.640563690969756 ips
怎么了 >_< ???提前致谢!
您是否对 Makefile 进行了一些更改,在 Makefile 中启用了 GPU 和 CUDNN。注意路径。
克隆 https://github.com/thtrieu/darkflow,
从 https://pjreddie.com/darknet/yolo/、
下载必要的 .cfg 和权重
将它们分别保存在 darkflow-master 中的 cfg 文件夹和一个新的 bin 文件夹中。
conda create -n darkflow-env python=3.6
activate darkflow-env
pip install tensorflow-gpu
(pip,不是conda。这一步应该也会自动安装CUDA和cuDNN,不需要单独下载。)
conda install cython numpy
conda config --add channels conda-forge
conda install opencv
转到您的 darkflow-master 文件夹并复制路径
cd 到路径(仍然使用 Anaconda Prompt)
python setup.py build_ext --inplace
python flow --model cfg/yolo.cfg --load bin/yolov2.weights --demo videofile.mp4 --saveVideo --gpu 0.7
(videofile.mp4是要渲染的视频,我直接放在darkflow-master文件夹下)
稍等一下,您会在 darkflow-master 文件夹中看到输出视频(在我的 GTX1050 TI 显卡笔记本电脑上,渲染速度约为 8.5 FPS)。
如果遇到需要Microsoft Visual C++ Build Tools之类的问题,那么只需从Microsoft网站下载,记得在安装的同时安装SDK。有关此问题的更多信息,您可以参考 https://github.com/thtrieu/darkflow/issues/788。