OSError: libdarknet.so: cannot open shared object file: No such file or directory 报错问题

测试yolov3 Python接口时会报错,看看如何解决。

1.下载yolov3。

地址: git clone https://github.com/pjreddie/darknet.git

2.修改makefile,编译。

3.将python文件夹下darknet.py放到和libdarknet.so同目录,执行python darknet.py 报错。

ycc@ycc:~/darknet$ python darknet.py 
  File "darknet.py", line 154
    print 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)
lib.network_width.argtypes = [c_void_p]
lib.network_width.restype = c_int
lib.network_height.argtypes = [c_void_p]
lib.network_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 128
   98 route  97 36
   99 conv    128  1 x 1 / 1    76 x  76 x 384   ->    76 x  76 x 128  0.568 BFLOPs
  100 conv    256  3 x 3 / 1    76 x  76 x 128   ->    76 x  76 x 256  3.407 BFLOPs
  101 conv    128  1 x 1 / 1    76 x  76 x 256   ->    76 x  76 x 128  0.379 BFLOPs
  102 conv    256  3 x 3 / 1    76 x  76 x 128   ->    76 x  76 x 256  3.407 BFLOPs
  103 conv    128  1 x 1 / 1    76 x  76 x 256   ->    76 x  76 x 128  0.379 BFLOPs
  104 conv    256  3 x 3 / 1    76 x  76 x 128   ->    76 x  76 x 256  3.407 BFLOPs
  105 conv    255  1 x 1 / 1    76 x  76 x 256   ->    76 x  76 x 255  0.754 BFLOPs
  106 yolo
Loading 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))]

成功运行。

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

学术菜鸟小晨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值