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

ValueError: Invalid tensor size. #234

Open flhsflhs opened 4 years ago

flhsflhs commented 4 years ago

I0923 17:27:08.678538 22616 convert_tflite.py:53] tflite model loaded [{'name': 'input_1', 'index': 0, 'shape': array([ 1, 416, 416, 3]), 'shape_signature': array([ -1, 416, 416, 3]), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}] [{'name': 'Identity', 'index': 937, 'shape': array([1, 1, 1]), 'shape_signature': array([-1, -1, -1]), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}] Traceback (most recent call last): File "convert_tflite.py", line 76, in <module> app.run(main) File "E:\Anaconda3\envs\tf2\lib\site-packages\absl\app.py", line 300, in run _run_main(main, args) File "E:\Anaconda3\envs\tf2\lib\site-packages\absl\app.py", line 251, in _run_main sys.exit(main(argv)) File "convert_tflite.py", line 72, in main demo() File "convert_tflite.py", line 66, in demo output_data = [interpreter.get_tensor(output_details[i]['index']) for i in range(len(output_details))] File "convert_tflite.py", line 66, in <listcomp> output_data = [interpreter.get_tensor(output_details[i]['index']) for i in range(len(output_details))] File "E:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\lite\python\interpreter.py", line 459, in get_tensor return self._interpreter.GetTensor(tensor_index) ValueError: Invalid tensor size.

When I converted yolov4.weights to yolov4.tflite, I encountered the following problems. The save_model.py file was successfully run, but an error ‘’123’’ was reported when the convert_tflite.py file was run. Either run the command'python convert_tflite.py --weights ./data/yolov4.weights --output ./data/yolov4.tflite' or run the command'python convert_tflite.py --weights ./data/yolov4.weights- -output ./data/yolov4-fp16.tflite --quantize_mode float16' is the same error, how can I solve this problem?

atomrun39 commented 4 years ago

I also encountered the same problem as you, have you solved it?

tomkisiela commented 4 years ago

Hello, same here but with yolov3 did someone manage to resolve this ?

flhsflhs commented 4 years ago

I also encountered the same problem as you, have you solved it?

I haven't solved this problem so far, and I have given up on solving this problem. This problem only appears when I generate float16 model files. There were no problems when running 'python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416.tflite'and 'python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416-int8.tflite --quantize_mode int8 --dataset ./coco_dataset/coco/val207.txt'. And all can run through detect.py smoothly. But there are always problems when deploying to android. So I have given up on solving this problem. I have successfully trained on the official demo provided by tensorflow_lite and successfully deployed on android.

tomkisiela commented 4 years ago

Could you share a link of the official demo please ? I'm not sure to know of which part you are talking. Is it this one ? https://colab.research.google.com/github/tensorflow/tensorflow/blob/master/tensorflow/lite/micro/examples/hello_world/train/train_hello_world_model.ipynb

flhsflhs commented 4 years ago

Train through this link: https://github.com/tensorflow/models Deploy the demo provided in this link: https://github.com/tensorflow/examples

tomkisiela commented 4 years ago

Thanks !

leekyungchoon commented 4 years ago

I also encountered the same problem as you, have you solved it?

I haven't solved this problem so far, and I have given up on solving this problem. This problem only appears when I generate float16 model files. There were no problems when running 'python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416.tflite'and 'python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416-int8.tflite --quantize_mode int8 --dataset ./coco_dataset/coco/val207.txt'. And all can run through detect.py smoothly. But there are always problems when deploying to android. So I have given up on solving this problem. I have successfully trained on the official demo provided by tensorflow_lite and successfully deployed on android.

I0923 17:27:08.678538 22616 convert_tflite.py:53] tflite model loaded [{'name': 'input_1', 'index': 0, 'shape': array([ 1, 416, 416, 3]), 'shape_signature': array([ -1, 416, 416, 3]), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}] [{'name': 'Identity', 'index': 937, 'shape': array([1, 1, 1]), 'shape_signature': array([-1, -1, -1]), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}] Traceback (most recent call last): File "convert_tflite.py", line 76, in <module> app.run(main) File "E:\Anaconda3\envs\tf2\lib\site-packages\absl\app.py", line 300, in run _run_main(main, args) File "E:\Anaconda3\envs\tf2\lib\site-packages\absl\app.py", line 251, in _run_main sys.exit(main(argv)) File "convert_tflite.py", line 72, in main demo() File "convert_tflite.py", line 66, in demo output_data = [interpreter.get_tensor(output_details[i]['index']) for i in range(len(output_details))] File "convert_tflite.py", line 66, in <listcomp> output_data = [interpreter.get_tensor(output_details[i]['index']) for i in range(len(output_details))] File "E:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\lite\python\interpreter.py", line 459, in get_tensor return self._interpreter.GetTensor(tensor_index) ValueError: Invalid tensor size.

When I converted yolov4.weights to yolov4.tflite, I encountered the following problems. The save_model.py file was successfully run, but an error ‘’123’’ was reported when the convert_tflite.py file was run. Either run the command'python convert_tflite.py --weights ./data/yolov4.weights --output ./data/yolov4.tflite' or run the command'python convert_tflite.py --weights ./data/yolov4.weights- -output ./data/yolov4-fp16.tflite --quantize_mode float16' is the same error, how can I solve this problem?

When trying to run save_model.py, run it with "--framework tflite" option, then try to convert it to tflite using convert_tflite.py. It worked for me.

shahshawaiz commented 3 years ago

I also encountered the same problem as you, have you solved it?

I haven't solved this problem so far, and I have given up on solving this problem. This problem only appears when I generate float16 model files. There were no problems when running 'python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416.tflite'and 'python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416-int8.tflite --quantize_mode int8 --dataset ./coco_dataset/coco/val207.txt'. And all can run through detect.py smoothly. But there are always problems when deploying to android. So I have given up on solving this problem. I have successfully trained on the official demo provided by tensorflow_lite and successfully deployed on android.

I0923 17:27:08.678538 22616 convert_tflite.py:53] tflite model loaded [{'name': 'input_1', 'index': 0, 'shape': array([ 1, 416, 416, 3]), 'shape_signature': array([ -1, 416, 416, 3]), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}] [{'name': 'Identity', 'index': 937, 'shape': array([1, 1, 1]), 'shape_signature': array([-1, -1, -1]), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}] Traceback (most recent call last): File "convert_tflite.py", line 76, in <module> app.run(main) File "E:\Anaconda3\envs\tf2\lib\site-packages\absl\app.py", line 300, in run _run_main(main, args) File "E:\Anaconda3\envs\tf2\lib\site-packages\absl\app.py", line 251, in _run_main sys.exit(main(argv)) File "convert_tflite.py", line 72, in main demo() File "convert_tflite.py", line 66, in demo output_data = [interpreter.get_tensor(output_details[i]['index']) for i in range(len(output_details))] File "convert_tflite.py", line 66, in <listcomp> output_data = [interpreter.get_tensor(output_details[i]['index']) for i in range(len(output_details))] File "E:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\lite\python\interpreter.py", line 459, in get_tensor return self._interpreter.GetTensor(tensor_index) ValueError: Invalid tensor size. When I converted yolov4.weights to yolov4.tflite, I encountered the following problems. The save_model.py file was successfully run, but an error ‘’123’’ was reported when the convert_tflite.py file was run. Either run the command'python convert_tflite.py --weights ./data/yolov4.weights --output ./data/yolov4.tflite' or run the command'python convert_tflite.py --weights ./data/yolov4.weights- -output ./data/yolov4-fp16.tflite --quantize_mode float16' is the same error, how can I solve this problem?

When trying to run save_model.py, run it with "--framework tflite" option, then try to convert it to tflite using convert_tflite.py. It worked for me.

Worked for me...

Thanks a bunch!! :)

leduy99 commented 3 years ago

I also encountered the same problem as you, have you solved it?

I haven't solved this problem so far, and I have given up on solving this problem. This problem only appears when I generate float16 model files. There were no problems when running 'python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416.tflite'and 'python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416-int8.tflite --quantize_mode int8 --dataset ./coco_dataset/coco/val207.txt'. And all can run through detect.py smoothly. But there are always problems when deploying to android. So I have given up on solving this problem. I have successfully trained on the official demo provided by tensorflow_lite and successfully deployed on android.

I0923 17:27:08.678538 22616 convert_tflite.py:53] tflite model loaded [{'name': 'input_1', 'index': 0, 'shape': array([ 1, 416, 416, 3]), 'shape_signature': array([ -1, 416, 416, 3]), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}] [{'name': 'Identity', 'index': 937, 'shape': array([1, 1, 1]), 'shape_signature': array([-1, -1, -1]), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}] Traceback (most recent call last): File "convert_tflite.py", line 76, in <module> app.run(main) File "E:\Anaconda3\envs\tf2\lib\site-packages\absl\app.py", line 300, in run _run_main(main, args) File "E:\Anaconda3\envs\tf2\lib\site-packages\absl\app.py", line 251, in _run_main sys.exit(main(argv)) File "convert_tflite.py", line 72, in main demo() File "convert_tflite.py", line 66, in demo output_data = [interpreter.get_tensor(output_details[i]['index']) for i in range(len(output_details))] File "convert_tflite.py", line 66, in <listcomp> output_data = [interpreter.get_tensor(output_details[i]['index']) for i in range(len(output_details))] File "E:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\lite\python\interpreter.py", line 459, in get_tensor return self._interpreter.GetTensor(tensor_index) ValueError: Invalid tensor size. When I converted yolov4.weights to yolov4.tflite, I encountered the following problems. The save_model.py file was successfully run, but an error ‘’123’’ was reported when the convert_tflite.py file was run. Either run the command'python convert_tflite.py --weights ./data/yolov4.weights --output ./data/yolov4.tflite' or run the command'python convert_tflite.py --weights ./data/yolov4.weights- -output ./data/yolov4-fp16.tflite --quantize_mode float16' is the same error, how can I solve this problem?

When trying to run save_model.py, run it with "--framework tflite" option, then try to convert it to tflite using convert_tflite.py. It worked for me.

Woa, you really did me a favor! Huge thanks :D