Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yolov3 slow? #2

Open
yuntai opened this issue Jul 12, 2019 · 8 comments
Open

Yolov3 slow? #2

yuntai opened this issue Jul 12, 2019 · 8 comments
Labels
good first issue

Comments

@yuntai
Copy link

@yuntai yuntai commented Jul 12, 2019

with video_demo.py about 20% speed compared to your 1.0 repo. but thanks much for sharing!

@yuntai yuntai changed the title slow? Yolov3 slow? Jul 12, 2019
@YunYang1994
Copy link
Owner

@YunYang1994 YunYang1994 commented Jul 12, 2019

please install tensorflow-gpu !!!

@YunYang1994
Copy link
Owner

@YunYang1994 YunYang1994 commented Jul 13, 2019

maybe it could be faster if you use frozen graph ".pb". I am not very sure about it. I will continuously update this repo, welcome to watch it !

@yuntai
Copy link
Author

@yuntai yuntai commented Jul 13, 2019

in utils.load_weights() got valueError: No such layer: batch_normalization_v2 with 2.0.0-beta1
w/o _v2 it works fine

@YunYang1994
Copy link
Owner

@YunYang1994 YunYang1994 commented Jul 14, 2019

Thank you. I fixed it just now.

@yuntai
Copy link
Author

@yuntai yuntai commented Jul 20, 2019

pred_bbox = model.predict(image_data) is much faster; not as fast as your tf1 repo though.

model(x) vs. model.predict(x)
When calling model(x) directly, we are executing the graph in eager mode. For model.predict, tf actually compiles the graph on the first run and then execute in graph mode. So if you are only running the model once, model(x) is faster since there is no compilation needed. Otherwise, model.predict or using exported SavedModel graph is much faster (by 2x).

from this

@YunYang1994
Copy link
Owner

@YunYang1994 YunYang1994 commented Jul 21, 2019

Thanks a lot for your valuable information

@YunYang1994 YunYang1994 added the good first issue label Jul 24, 2019
@yuntai
Copy link
Author

@yuntai yuntai commented Jul 29, 2019

this gives a bit of speed-up. very roughly ~ 20 fps to ~ 30 fps on ti1080ti.

feature_maps = YOLOv3(input_layer)

@tf.function
def build(feature_maps):
    bbox_tensors = []
    for i, fm in enumerate(feature_maps):
        bbox_tensor = decode(fm, i)
        bbox_tensors.append(tf.reshape(bbox_tensor, (-1, 5+num_classes)))
    bbox_tensors = tf.concat(bbox_tensors, axis=0)
    return bbox_tensors

bbox_tensors = build(feature_maps)
model = tf.keras.Model(input_layer, bbox_tensors)

Think I will come back this speed issue when (non-beta) v2.0 is released.

BTW, I found a small optimization in 'postprocess_boxes()' where we can filter with score_mask first to significantly reduce the number of rows to be processed in the following. perhaps a couple of fps gain! :)

@yuntai
Copy link
Author

@yuntai yuntai commented Aug 3, 2019

for some reason predict_on_batch(image) is much faster! (almost twice). tried predict(image, batch_size=1) but still slow. with this & tf.function above I think, now, the speed is par with that of your tf1 repo. congrats & thanks!

I had a problem with tf.function with official tf2.0-beta-gpu. but with my own custom 2.0 build (don't know which source commit I used) it works fine. I think it's correct usage and okay when the release version comes out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue
Projects
None yet
Development

No branches or pull requests

2 participants