选择要用的GPU: CUDA_VISIBLE_DEVICES
在JetsonNX中使用PaddleHUB,要使用GPU来做目标检测时,出错,测试代码很简单:
import paddlehub as hub
import cv2
object_detector = hub.Module(name="yolov3_darknet53_coco2017")
result = object_detector.object_detection(images=[cv2.imread('/home/nx/Pictures/kite.jpg')], use_gpu=True ,visualization=True)
print(result)
提示错误
nx@nx-desktop:~/mysoft/paddle_test$ python3 object_detect.py
[2020-12-11 14:34:18,790] [ INFO] - Installing yolov3_darknet53_coco2017 modu le
[2020-12-11 14:34:18,992] [ INFO] - Module yolov3_darknet53_coco2017 already installed in /home/nx/.paddlehub/modules/yolov3_darknet53_coco2017
/usr/lib/python3/dist-packages/apport/report.py:13: DeprecationWarning: the impmodule is deprecated in favour of importlib; see the module's documentation for alternative uses
import fnmatch, glob, traceback, errno, sys, atexit, locale, imp, stat
Traceback (most recent call last):
File "/home/nx/.paddlehub/modules/yolov3_darknet53_coco2017/module.py", line 185, in object_detection
_places = os.environ["CUDA_VISIBLE_DEVICES"]
File "/usr/lib/python3.6/os.py", line 669, in __getitem__
raise KeyError(key) from None
KeyError: 'CUDA_VISIBLE_DEVICES'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "object_detect.py", line 22, in <module>
result = object_detector.object_detection(images=[cv2.imread('/home/nx/Pictures/kite.jpg')], use_gpu=True ,visualization=True)
File "/home/nx/.paddlehub/modules/yolov3_darknet53_coco2017/module.py", line 189, in object_detection
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
RuntimeError: Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly.
提示要设置“CUDA_VISIBLE_DEVICES”
不知道怎么弄,查找“CUDA_VISIBLE_DEVICES”,找到文章
选择要用的GPU: CUDA_VISIBLE_DEVICES
设置
linux:
在~/.bashrc 的最后加上export CUDA_VISIBLE_DEVICES=1,然后source ~/.bashrc
windows:
打开我的电脑环境变量设置的地方,直接添加就行了。