Open phil100vol opened 4 years ago
It seems you wrote this code for an older version of darknet.py prior to the changes made in 52c7314. The newest version of darknet.py has changed in some subtle ways. I suggest checking out https://github.com/AlexeyAB/darknet/blob/master/darknet_images.py for examples of how the newer version can be called.
You will need to change your code here:
netMain = darknet.load_net_custom(configPath.encode("ascii"), weightPath.encode("ascii"), 0, 1)
metaMain = darknet.load_meta(metaPath.encode("ascii"))
to be compatable with the newer version to something along these lines:
network, class_names, class_colors = darknet.load_network(configPath, metaPath, weightPath, batch_size=1)
and then change your old call to detect_image:
detections = darknet.detect_image(netMain, metaMain, darknet_image, thresh=0.25)
to something more along these lines:
detections = darknet.detect_image(network, class_names, darknet_image, thresh=0.25)
And finally within your cvDrawBoxes function:
for detection in detections:
x, y, w, h = detection[2][0],\
detection[2][1],\
detection[2][2],\
detection[2][3]
name_tag = str(detection[0].decode())
Will need to be changed to something along the lines of:
for label, confidence, bbox in detections:
x, y, w, h = (bbox[0],
bbox[1],
bbox[2],
bbox[3])
name_tag = label
and finally any reference to detection[1]
in cvDrawBoxes should be changed to confidence
Hopefully I hit all of the major points here but I can't guarantee I caught every error. I recently had to update some older code as well and was having the same error so hope this helps. My code seems to be working after all of these fixes.
@eandert I got the same error and thanks to you, your solution works for me.
netMain = darknet.load_net_custom(configPath.encode("ascii"), weightPath.encode("ascii"), 0, 1) metaMain = darknet.load_meta(metaPath.encode("ascii"))
do i have to change these lines with network, class_names, class_colors = darknet.load_network(configPath, metaPath, weightPath, batch_size=1) these?
also helpful for me, same issue
@eandert YOU ROCK!. You saved me hours of headache. Thank you so much! And to the people who are not sure about @eandert answer's because he/she wrote "along these lines", try to do exactly what he/she said. It worked for me.
Namely replace each of netMain = darknet.load_net_custom(configPath.encode("ascii"), weightPath.encode("ascii"), 0, 1) and metaMain = darknet.load_meta(metaPath.encode("ascii")) with network, class_names, class_colors = darknet.load_network(configPath, metaPath, weightPath, batch_size=1)
detections = darknet.detect_image(netMain, metaMain, darknet_image, thresh=0.25) with detections = darknet.detect_image(network, class_names, darknet_image, thresh=0.25)
as well as the modifications in the for loop! Try it it works.
Thanks again @eandert
Hi,
I want to detect objects on my rtsp stream. Unfortunate the code ends in the following error:
My minimal example looks like that:
Hope someone can give me a hand. Thanks
Phil