hunglc007 / tensorflow-yolov4-tflite

YOLOv4, YOLOv4-tiny, YOLOv3, YOLOv3-tiny Implemented in Tensorflow 2.0, Android. Convert YOLO v4 .weights tensorflow, tensorrt and tflite
https://github.com/hunglc007/tensorflow-yolov4-tflite
MIT License
2.23k stars 1.24k forks source link

detect.py tf framework - failed to read all data #118

Closed aselva-eb closed 4 years ago

aselva-eb commented 4 years ago

Hello,

Trying to run the basic detect.py demo using the yolo4.weights from the download link provided.

However I run into the following issue:

  File "detect.py", line 112, in <module>
    app.run(main)
  File "/Users/abc/miniconda3/envs/yolov4/lib/python3.7/site-packages/absl/app.py", line 299, in run
    _run_main(main, args)
  File "/Users/abc/miniconda3/envs/yolov4/lib/python3.7/site-packages/absl/app.py", line 250, in _run_main
    sys.exit(main(argv))
  File "detect.py", line 56, in main
    utils.load_weights_tiny(model, FLAGS.weights, FLAGS.model)
  File "/Users/abs/object_detection/tensorflow-yolov4-tflite/core/utils.py", line 51, in load_weights_tiny
    assert len(wf.read()) == 0, 'failed to read all data'

Here's the command I'm using:

python detect.py --weights ./data/yolov4.weights --framework tf --size 416 --image ./data/kite.jpg --tiny yolo --model yolov4

I haven't modified the repo in any way

hunglc007 commented 4 years ago

This issue are fixed in newest code

aselva-eb commented 4 years ago

I tried running the new instructions for the demo, by first converting the weights to a saved model:

(python save_model.py --weights ./data/yolov4.weights --output ./checkpoints/yolov4-416 --input_size 416 --model yolov4) However it fails with the following error:

Traceback (most recent call last):
  File "/Users/abc/miniconda3/envs/yolov4/lib/python3.7/site-packages/tensorflow_core/python/ops/gen_array_ops.py", line 10392, in tile
    input, multiples)
tensorflow.python.eager.core._FallbackException: This function does not handle the case of the path where all inputs are not already EagerTensors.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/abc/miniconda3/envs/yolov4/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 1619, in _create_c_op
    c_op = c_api.TF_FinishOperation(op_desc)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Duplicate node name in graph: 'packed'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "save_model.py", line 60, in <module>
    app.run(main)
  File "/Users/abc/miniconda3/envs/yolov4/lib/python3.7/site-packages/absl/app.py", line 299, in run
    _run_main(main, args)
  File "/Users/abc/miniconda3/envs/yolov4/lib/python3.7/site-packages/absl/app.py", line 250, in _run_main
    sys.exit(main(argv))
  File "save_model.py", line 56, in main
    save_tf()
  File "save_model.py", line 36, in save_tf
    output_tensors = decode(fm, FLAGS.input_size // 16, NUM_CLASS, STRIDES, ANCHORS, i, XYSCALE, FLAGS.framework)
  File "/Users/abc/object_detection/tensorflow-yolov4-tflite/core/yolov4.py", line 169, in decode
    return decode_tf(conv_output, output_size, NUM_CLASS, STRIDES, ANCHORS, i=i, XYSCALE=XYSCALE)
  File "/Users/abc/object_detection/tensorflow-yolov4-tflite/core/yolov4.py", line 180, in decode_tf
    xy_grid = tf.tile(tf.expand_dims(xy_grid, axis=0), [tf.shape(conv_output)[0], 1, 1, 3, 1])
  File "/Users/abc/miniconda3/envs/yolov4/lib/python3.7/site-packages/tensorflow_core/python/ops/gen_array_ops.py", line 10397, in tile
    input, multiples, name=name, ctx=_ctx)
  File "/Users/abc/miniconda3/envs/yolov4/lib/python3.7/site-packages/tensorflow_core/python/ops/gen_array_ops.py", line 10433, in tile_eager_fallback
    _attr_Tmultiples, (multiples,) = _execute.args_to_matching_eager([multiples], ctx, _dtypes.int32)
  File "/Users/abc/miniconda3/envs/yolov4/lib/python3.7/site-packages/tensorflow_core/python/eager/execute.py", line 263, in args_to_matching_eager
    t, dtype, preferred_dtype=default_dtype, ctx=ctx))
  File "/Users/abc/miniconda3/envs/yolov4/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 1314, in convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "/Users/abc/miniconda3/envs/yolov4/lib/python3.7/site-packages/tensorflow_core/python/ops/array_ops.py", line 1368, in _autopacking_conversion_function
    return _autopacking_helper(v, dtype, name or "packed")
  File "/Users/abc/miniconda3/envs/yolov4/lib/python3.7/site-packages/tensorflow_core/python/ops/array_ops.py", line 1304, in _autopacking_helper
    return gen_array_ops.pack(elems_as_tensors, name=scope)
  File "/Users/abc/miniconda3/envs/yolov4/lib/python3.7/site-packages/tensorflow_core/python/ops/gen_array_ops.py", line 5704, in pack
    "Pack", values=values, axis=axis, name=name)
  File "/Users/abc/miniconda3/envs/yolov4/lib/python3.7/site-packages/tensorflow_core/python/framework/op_def_library.py", line 742, in _apply_op_helper
    attrs=attr_protos, op_def=op_def)
  File "/Users/abc/miniconda3/envs/yolov4/lib/python3.7/site-packages/tensorflow_core/python/framework/func_graph.py", line 595, in _create_op_internal
    compute_device)
  File "/Users/abc/miniconda3/envs/yolov4/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 3322, in _create_op_internal
    op_def=op_def)
  File "/Users/abc/miniconda3/envs/yolov4/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 1786, in __init__
    control_input_ops)
  File "/Users/abc/miniconda3/envs/yolov4/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 1622, in _create_c_op
    raise ValueError(str(e))
ValueError: Duplicate node name in graph: 'packed'
aselva-eb commented 4 years ago

^ I also get a similar issue when trying on the yolov4-tiny.weights model from the weights I downloaded online. Do you have a hosted version that works?

aselva-eb commented 4 years ago

This issue is resolved with TF version 2.3.0rc0. I hadn't realized the prerequisite changed.

Might want to update the requirements file!

Thanks for resolving this! 💯