Darknet: ArgumentError in darknet.py after fixing syntax error

Created on 10 Oct 2017  路  14Comments  路  Source: pjreddie/darknet

running python darknet.py results in this error for me:
Traceback (most recent call last): File "darknet.py", line 122, in <module> net = load_net("cfg/tiny-yolo.cfg", "tiny-yolo.weights", 0) ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type
Inbefore I fixed the path in line 35 (it didn't find libdarknet.so) and added brackets to the print statement in line 125. These being the only changes, I wonder why ctypes throws a ArgumentError, when all the values are as they should be (and I didn't change them from the original source code). Is the wrapper actually working ?

Python:
Python 3.6.1 |Anaconda custom (64-bit)| (default, May 11 2017, 13:09:58) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux Type "help", "copyright", "credits" or "license" for more information.

Makefile (only changed lines):
GPU=1 CUDNN=1 OPENCV=1

System:
Ubuntu 16.04 GNOME 3
Intel Core i7 5820K
Nvidia TITAN Xp

All dependencies (CUDA, OPENCV, etc) work fine with other projects, so that shouldn't be the problem.

Please help?:)

Most helpful comment

the <class 'TypeError'> is due the passing of string from python to c/c++ lib. just add 'b' before your string like load_net(b"/path/darknet/cfg/yolo-lines.cfg",b"/path/darknet/backup/yolo-lines_63000.weights", 0)

For string variables use bytes(str_variable, encoding='utf-8')

All 14 comments

I'm experiencing the same issue and updated all paths in the file.

python/darknet.py
Traceback (most recent call last):
  File "python/darknet.py", line 65, in <module>
    net = load_net("/mypath/cfg/yolo.cfg", "/mypath/backup/yolo_50000.weights")
  File "python/darknet.py", line 28, in load_net
    return load_network(cfg, weights, 0)
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type

I am trying to use proverbot.py , also have this problem
net = load_net("/path/darknet/cfg/yolo-lines.cfg","/path/darknet/backup/yolo-lines_63000.weights", 0) ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type

I've managed to get detections in python by using this wrapper instead https://github.com/digitalbrain79/pyyolo

the <class 'TypeError'> is due the passing of string from python to c/c++ lib. just add 'b' before your string like load_net(b"/path/darknet/cfg/yolo-lines.cfg",b"/path/darknet/backup/yolo-lines_63000.weights", 0)

For string variables use bytes(str_variable, encoding='utf-8')

Following @ashish1405 - when calling the C functions from python3, add encode('utf-8') for string input. E.g.:

net = load_net(net_filename.encode('utf-8'), weights_filename.encode('utf-8'), 0)
meta = load_meta(meta_filename.encode('utf-8'))
r = detect(net, meta, jpg_filename.encode('utf-8'))

@mousomer I'm not a python expert, but won't the string.encode('utf-8') convert the python string to python string('utf-8'). But the C functions require char array, so the conversion to bytes.

@ashish1405
Neither am I. But - look at:

In [1]: 'fff'.encode('utf-8')
Out[1]: b'fff'

So, the encode() string function does indeed convert to char array. In any case, the code above works for me (python 3.6)

oh yes, that's correct 馃憤 . Sometimes it is difficult to predict how python behaves :)

There's actually a python doc about this:
https://docs.python.org/3/howto/unicode.html#converting-to-bytes

@mousomer Converting to UTF-8 solves the problem for Python 3. Thanks.
(For Python 2, that's not required.)

Hi, I change the line net = load_net("cfg/yolov3-tiny.cfg", "yolov3-tiny.weights", 0) to net = load_net("cfg/yolov3-tiny.cfg".encode("utf-8"), "yolov3-tiny.weights".encode("utf-8"), 0).
But, I faced the error as below:
OSError: exception: access violation writing 0x000000000022E800 _(0x[something somthing])_
or
OSError: exception: access violation reading 0x000000000022E800 _(0x[something somthing])_
Maybe this problem is because of my OS (Windows 7)?

Probably it is.
On MS Windows I would expect it to work without re-encoding to UTF-8. If that doesn't help you try a different encoding.

the <class 'TypeError'> is due the passing of string from python to c/c++ lib. just add 'b' before your string like load_net(b"/path/darknet/cfg/yolo-lines.cfg",b"/path/darknet/backup/yolo-lines_63000.weights", 0)

For string variables use bytes(str_variable, encoding='utf-8')

That can be solve the py3 problem.

@pjreddie wouldn't it be a good idea to implement the bytes conversion as a permanent fix of this problem and thus upgrade the Python module to Python 3? After all, Python 2.7 is not supported anymore. I can submit a pull request if you like.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Vikalp-Reorder picture Vikalp-Reorder  路  3Comments

HoracceFeng picture HoracceFeng  路  3Comments

gpsmit picture gpsmit  路  3Comments

job2003 picture job2003  路  3Comments

groot-1313 picture groot-1313  路  4Comments