测试yolov3 Python接口时会报错,看看如何解决。
1.下载yolov3。
地址:git clone /pjreddie/darknet.git
2.修改makefile,编译。
3.将python文件夹下darknet.py放到和libdarknet.so同目录,执行python darknet.py 报错。
ycc@ycc:~/darknet$ python darknet.py File "darknet.py", line 154print r^SyntaxError: Missing parentheses in call to 'print'. Did you mean print(r)?
解决:把 print r 改成print(r)。
ycc@ycc:~/darknet$ python darknet.py Traceback (most recent call last):File "darknet.py", line 48, in <module>lib = CDLL("libdarknet.so", RTLD_GLOBAL)File "/home/ycc/anaconda3/lib/python3.7/ctypes/__init__.py", line 356, in __init__self._handle = _dlopen(self._name, mode)OSError: libdarknet.so: cannot open shared object file: No such file or directory
解决:将libdarknet.so的路径改成绝对路径。
class METADATA(Structure):_fields_ = [("classes", c_int),("names", POINTER(c_char_p))]#lib = CDLL("/home/pjreddie/documents/darknet/libdarknet.so", RTLD_GLOBAL)lib = CDLL("/home/ycc/darknet/libdarknet.so", RTLD_GLOBAL)work_width.argtypes = [c_void_p]work_width.restype = work_height.argtypes = [c_void_p]work_height.restype = c_int
ycc@ycc:~/darknet$ python darknet.py Traceback (most recent call last):File "darknet.py", line 151, in <module>net = load_net("cfg/tiny-yolo.cfg", "tiny-yolo.weights", 0)ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type
解决:出错的字符串前加b
net = load_net(b"cfg/yolov3.cfg", b"yolov3.weights", 0)meta = load_meta(b"cfg/coco.data")r = detect(net, meta, b"data/dog.jpg")print (r)
97 upsample 2x 38 x 38 x 128 -> 76 x 76 x 12898 route 97 3699 conv 128 1 x 1 / 1 76 x 76 x 384 -> 76 x 76 x 128 0.568 BFLOPs100 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs101 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs102 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs103 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs104 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs105 conv 255 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 255 0.754 BFLOPs106 yoloLoading weights from yolov3.weights...Done![(b'dog', 0.9993329048156738, (224.17959594726562, 378.47900390625, 178.7544708251953, 328.2962341308594)), (b'bicycle', 0.991621732711792, (344.5289306640625, 286.759765625, 486.1888427734375, 321.36590576171875)), (b'truck', 0.9165933728218079, (580.9117431640625, 125.05439758300781, 208.13427734375, 87.27815246582031))]
成功运行。
如果觉得《OSError: libdarknet.so: cannot open shared object file: No such file or directory 报错问题》对你有帮助,请点赞、收藏,并留下你的观点哦!