AlexeyAB / darknet

YOLOv4 / Scaled-YOLOv4 / YOLO - Neural Networks for Object Detection (Windows and Linux version of Darknet )
http://pjreddie.com/darknet/
Other
21.75k stars 7.96k forks source link

How to batch process images in python? #6576

Open mazatov opened 4 years ago

mazatov commented 4 years ago

I am able to process images and video one frame at a time in python with my custom network but I can't seem to make batch processing work. I suspect it'll be faster that way. The load_network function has a batch_size as a parameter. Where does a batch_size go when I create darknet_image. Is it the first or last dimension? I tried both ways and can't seem to make it work. I get an empty detections list, while I do get a detection if I remove batch_size and create darknet_image without it.

batch_size = 4
netMain, class_names, colors = darknet.load_network(configPath, metaPath, weightPath,batch_size)
netdims = [darknet.network_width(netMain), darknet.network_height(netMain)]
darknet_image = darknet.make_image(batch_size,netdims[0],netdims[1],3)
frame_rgb = cv2.cvtColor(im, cv2.COLOR_BGR2RGB)      
frame_resized= cv2.resize(frame_rgb,(netdims[0],netdims[1]),interpolation=cv2.INTER_LINEAR)
f4 = np.stack((frame_resized,frame_resized,frame_resized,frame_resized),axis = 0)
darknet.copy_image_from_bytes(darknet_image,f4.tobytes())  
detections = darknet.detect_image(netMain, class_names, darknet_image, thresh=0.25)
print(detections)
LukeAI commented 4 years ago

bump

mazatov commented 4 years ago

bump

Upon some further investigation, I see that there is lib.network_predict_batch and lib.free_batch_detections + load_network has the ability to add batch_size so it seems like it should be doable.

It'll be nice to also have detect_images function that works on batches given that that's possible. Doesn't look like I can change they issue type but this should be a Feature Request.

mazatov commented 4 years ago

@LukeAI , any luck? Still haven't been able to figure it out

LukeAI commented 4 years ago

no