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

Not all yolov3 tiny models are supported #82

Open vinorth-v opened 4 years ago

vinorth-v commented 4 years ago

Hello everyone,

I have no problem when I convert to tflite when converting yolov4 models or yolov3 tiny models (with 2 yolo-layers).

However, when I want to convert yolov3 tiny-prn models or yolov3 tiny models (with 3 yolo-layers) to tflite models, I have the following errors:

Traceback (most recent call last):                                                                                                                                                                                 
  File "convert_tflite.py", line 115, in <module>                                                                                                                                                                  
    app.run(main)                                                                                                                                                                                                  
  File "/home/vinorth/anaconda3/envs/yolov4-tflite/lib/python3.7/site-packages/absl/app.py", line 299, in run                                                                                                      
    _run_main(main, args)                                                                                                                                                                                          
  File "/home/vinorth/anaconda3/envs/yolov4-tflite/lib/python3.7/site-packages/absl/app.py", line 250, in _run_main                                                                                                
    sys.exit(main(argv))                                                                                                                                                                                           
  File "convert_tflite.py", line 110, in main                                                                                                                                                                      
    save_tflite()                                                                                                                                                                                                  
  File "convert_tflite.py", line 45, in save_tflite                                                                                                                                                                
    utils.load_weights_tiny(model, FLAGS.weights)                                                                                                                                                                  
  File "/home/vinorth/tensorflow-yolov4-tflite/core/utils.py", line 45, in load_weights_tiny                                                                                                                       
    assert len(wf.read()) == 0, 'failed to read all data'                                                                                                                                                          
AssertionError: failed to read all data
Traceback (most recent call last):
  File "convert_tflite.py", line 115, in <module>
    app.run(main)
  File "/home/vinorth/anaconda3/envs/yolov4-tflite/lib/python3.7/site-packages/absl/app.py", line 299, in run
    _run_main(main, args)
  File "/home/vinorth/anaconda3/envs/yolov4-tflite/lib/python3.7/site-packages/absl/app.py", line 250, in _run_main
    sys.exit(main(argv))
  File "convert_tflite.py", line 110, in main
    save_tflite()
  File "convert_tflite.py", line 45, in save_tflite
    utils.load_weights_tiny(model, FLAGS.weights)
  File "/home/vinorth/tensorflow-yolov4-tflite/core/utils.py", line 37, in load_weights_tiny
    conv_weights = conv_weights.reshape(conv_shape).transpose([2, 3, 1, 0])
ValueError: cannot reshape array of size 3271862 into shape (1024,512,3,3)

Is it possible to support yolo3 models even if we add or remove layers? Thank you in advance

molimat commented 4 years ago

Yes, it is. But you should change your .\core\config.py file to your new class.names file as in this example. __C.YOLO.CLASSES = "./data/classes/custom.names"

Of course, this custom.names file has the same classes that I used to generate the weight file from darknet training.

This should be ok.