mystic123 / tensorflow-yolo-v3

Implementation of YOLO v3 object detector in Tensorflow (TF-Slim)
https://medium.com/@pawekapica_31302/implementing-yolo-v3-in-tensorflow-tf-slim-c3c55ff59dbe
Apache License 2.0
893 stars 353 forks source link

How to run inference with Tiny YoloV3 #103

Open sayakpaul opened 3 years ago

sayakpaul commented 3 years ago

Hi folks.

How should I run an inference with the frozen graph of Tiny YoloV3? I have been able to get the frozen graph by executing the convert_weights_pb.py but using the demo.py file I am not able to run inference.

Has anyone else faced a similar issue? Here's I execute the demo script -

python ./demo.py --input_img input.png --output_img output.png --frozen_model yolo.pb --tiny True
sayakpaul commented 3 years ago

So, here's what I did next. I generated the checkpoints instead of the frozen graph as this code block indicated so.

!python convert_weights.py --class_names "coco.names" --weights_file "yolov3-tiny.weights" --data_format "NHWC" --tiny True

Now, when I issued the following command I am running into error -

!python demo.py --input_img image2.jpg --output_img output.png --tiny True

I am running into -

Model restored in 0.09s
2020-12-13 10:20:03.542180: E tensorflow/core/common_runtime/executor.cc:642] Executor failed to create kernel. Invalid argument: Default MaxPoolingOp only supports NHWC on device type CPU
     [[{{node detector/yolo-v3-tiny/pool2/MaxPool}}]]
Traceback (most recent call last):
  File "/tensorflow-1.15.2/python3.6/tensorflow_core/python/client/session.py", line 1365, in _do_call
    return fn(*args)
  File "/tensorflow-1.15.2/python3.6/tensorflow_core/python/client/session.py", line 1350, in _run_fn
    target_list, run_metadata)
  File "/tensorflow-1.15.2/python3.6/tensorflow_core/python/client/session.py", line 1443, in _call_tf_sessionrun
    run_metadata)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Default MaxPoolingOp only supports NHWC on device type CPU
     [[{{node detector/yolo-v3-tiny/pool2/MaxPool}}]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "demo.py", line 105, in <module>
    tf.app.run()
  File "/tensorflow-1.15.2/python3.6/tensorflow_core/python/platform/app.py", line 40, in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 300, in run
    _run_main(main, args)
  File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "demo.py", line 92, in main
    boxes, feed_dict={inputs: [img_resized]})
  File "/tensorflow-1.15.2/python3.6/tensorflow_core/python/client/session.py", line 956, in run
    run_metadata_ptr)
  File "/tensorflow-1.15.2/python3.6/tensorflow_core/python/client/session.py", line 1180, in _run
    feed_dict_tensor, options, run_metadata)
  File "/tensorflow-1.15.2/python3.6/tensorflow_core/python/client/session.py", line 1359, in _do_run
    run_metadata)
  File "/tensorflow-1.15.2/python3.6/tensorflow_core/python/client/session.py", line 1384, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Default MaxPoolingOp only supports NHWC on device type CPU
     [[node detector/yolo-v3-tiny/pool2/MaxPool (defined at /tensorflow-1.15.2/python3.6/tensorflow_core/python/framework/ops.py:1748) ]]