allanzelener / YAD2K

YAD2K: Yet Another Darknet 2 Keras
Other
2.71k stars 877 forks source link

Batch in Testing #53

Open filipetrocadoferreira opened 7 years ago

filipetrocadoferreira commented 7 years ago

How can I setup the number of images to process in batch?

filipetrocadoferreira commented 7 years ago

When doing batch processing and using yolo_eval, the output of bounding boxes has the shape of [?,4] instead of [batch,?,4]

giulio-zhou commented 6 years ago

Also having this issue, any updates on why this is the case?

bhupinders commented 6 years ago

Hi guys, I ran into the same issue! Has anybody been able to run it on batches?

giulio-zhou commented 6 years ago

I implemented a workaround that appears to do the job. https://github.com/giulio-zhou/YAD2K/blob/master/yad2k/models/keras_yolo.py#L351-L400 I believe the issue is that when the original implementation applies a K.argmax to extract the highest scoring boxes, it's doing it over the entire tensor that gets produced in the batch inference (aka all of the input images at once). The result is then flattened (with non-maximal suppression applied) into boxes, scores, classes tensors that you see. My workaround explicitly defines the batch size - which you can't change - and creates TF graph nodes that extract the bounding boxes for each batch example separately. The results are concatenated, but then I use my frames tensor as an index into the other tensors. Hope this helps!

filipetrocadoferreira commented 6 years ago

@giulio-zhou I think you're right. I was planning doing something similar but never got the time. I will try to test your implementation. Did you checked performance gains?

giulio-zhou commented 6 years ago

The way that I used it was part of another pipeline that post-processed the bounding boxes right after running the network which is now the bottleneck. I need to separate those two out if I want to measure performance, which I have yet to do.

bhupinders commented 6 years ago

@giulio-zhou That workaround works, but getting slower predictions!! I didnt do any processing after getting the predictions (~ 2 seconds slower for 50 images)