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.25k stars 1.24k forks source link

run detect.py on yolov4-tflite - bbbox list index out of range #117

Closed aselva-eb closed 4 years ago

aselva-eb commented 4 years ago

Hello!

I'm trying to run the basic tflite demo but running into the following issue:

  File "detect.py", line 96, in main
    pred_bbox = utils.postprocess_bbbox(pred_bbox, ANCHORS, STRIDES, XYSCALE)
  File "/Users/abc/object_detection/tensorflow-yolov4-tflite/core/utils.py", line 319, in postprocess_bbbox
    pred_xy = ((tf.sigmoid(conv_raw_dxdy) * XYSCALE[i]) - 0.5 * (XYSCALE[i] - 1) + xy_grid) * STRIDES[i]
IndexError: list index out of range

Here is the command I use to run the model: python detect.py --weights ./data/yolov4.tflite --framework tflite --size 416 --image ./data/kite.jpg --tiny yolo-tiny --model yolov4

Anything I'm missing/doing wrong?

hunglc007 commented 4 years ago

This issue are fixed in newest code

aselva-eb commented 4 years ago

Hi @hunglc007 Thanks for making changes to address the issue. However I'm having a bit of issues running the tflite model:

Heres my flow:

  1. Convert the weights to saved model: python save_model.py --weights ./data/yolov4.weights --output ./checkpoints/yolov4-416 --input_size 416 --model yolov4 --framework tflite

  2. Convert to tflite file 16bit quantized: python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./data/yolov4-416-fp16.tflite --quantize_mode float16

  3. Run the detect with the tflite file as the weights python detect.py --weights ./data/yolov4-416-fp16.tflite --size 416 --model yolov4 --image ./data/kite.jpg --framework tflite

However I run into this error:

Traceback (most recent call last):
  File "detect.py", line 93, 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 62, in main
    boxes, pred_conf = filter_boxes(pred[1], pred[0], score_threshold=0.25)
  File "/Users/abc/object_detection/tensorflow-yolov4-tflite/core/yolov4.py", line 258, in filter_boxes
    box_xy, box_wh = tf.split(class_boxes, (2, 2), axis=-1)
  File "/Users/abc/miniconda3/envs/yolov4/lib/python3.7/site-packages/tensorflow/python/util/dispatch.py", line 201, in wrapper
    return target(*args, **kwargs)
  File "/Users/abc/miniconda3/envs/yolov4/lib/python3.7/site-packages/tensorflow/python/ops/array_ops.py", line 2026, in split
    value=value, size_splits=size_splits, axis=axis, num_split=num, name=name)
  File "/Users/abc/miniconda3/envs/yolov4/lib/python3.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 9945, in split_v
    _ops.raise_from_not_ok_status(e, name)
  File "/Users/abc/miniconda3/envs/yolov4/lib/python3.7/site-packages/tensorflow/python/framework/ops.py", line 6843, in raise_from_not_ok_status
    six.raise_from(core._status_to_exception(e.code, message), None)
  File "<string>", line 3, in raise_from
tensorflow.python.framework.errors_impl.InvalidArgumentError: Determined shape must either match input shape along split_dim exactly if fully specified, or be less than the size of the input along split_dim if not fully specified.  Got: 4 [Op:SplitV] name: split

Am I following the instructions incorrectly? Also, can I expect to be able to follow the same instructions for tflite using the yolov4-tiny weights?

hunglc007 commented 4 years ago

Because i set default tiny is True, this issue are fixed.

aselva-eb commented 4 years ago

Thank you