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

Converting from YOLOv4 .weights to .tflite results in NaN #201

Open KLT1003 opened 4 years ago

KLT1003 commented 4 years ago

My .weights generated via (https://towardsdatascience.com/yolov4-in-google-colab-train-your-custom-dataset-traffic-signs-with-ease-3243ca91c81d) are working fine. But after I start the converting steps to .pb and .tflite it stops working during inference on my android device. I can see some NaNs during convert_tflite.py, but I have no idea how to proceed from here. Please advise.

...
  [[0.93409395 0.5745914  0.02634688]
   [0.43668228 0.76611984 0.6618048 ]
   [0.42292097 0.7411889  0.13989629]
   ...
   [0.39483282 0.49909568 0.74120367]
   [0.5637653  0.12396393 0.4660843 ]
   [0.752046   0.82580703 0.5173879 ]]

  [[0.6689899  0.35510162 0.32931304]
   [0.96155727 0.89291227 0.20130242]
   [0.5370816  0.9430978  0.5371436 ]
   ...
   [0.19491003 0.27313858 0.03304826]
   [0.41672257 0.11767507 0.07572859]
   [0.6832552  0.6121169  0.24327564]]

  [[0.2700934  0.3082906  0.7143617 ]
   [0.15999225 0.6401019  0.95718765]
   [0.28765443 0.79288983 0.56558126]
   ...
   [0.760959   0.55497843 0.41802663]
   [0.02423805 0.11752898 0.20009235]
   [0.03073508 0.36121124 0.7559383 ]]]]
<class 'int'>
[array([[[nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan],
        ...,
        [nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan]]], dtype=float32), array([[[nan, nan, nan, nan],
        [nan, nan, nan, nan],
        [nan, nan, nan, nan],
        ...,
        [nan, nan, nan, nan],
        [nan, nan, nan, nan],
        [nan, nan, nan, nan]]], dtype=float32)]
zhang0225 commented 3 years ago

hello,i am doing the same work and i do not konw how to convert my yolov4.weights to tflite,could you give me some suggestions?

yp19940913 commented 3 years ago

Hello, I have encountered the same problem. Have you solved it now? How? @KLT1003 @zhang0225

zhang0225 commented 3 years ago

Hello, I have encountered the same problem. Have you solved it now? How? @KLT1003 @zhang0225

Hi,Firstly,you need to satisify the requirements,and then,please use save_model.py to convert .weigths to tf model.finally,use convert_tflite.py to convert tf model to tflite,you can reference to the commands mentioned by author

KLT1003 commented 3 years ago

@yp19940913 No unfortunately I haven't been able to solve this issue. I've tried both via .weights -> .pb -> .tflite and .weights -> .h5 -> .tflite to no avail. FWIW: TFLite and probably also the TFLiteConverter only supports SSD based models for object detection (which is my desired use case) according to https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/running_on_mobile_tf2.md

yp19940913 commented 3 years ago

After run save_model.py, i found when two file named model.data and model.index were put into the folder named /checkpoints/yolov4-tiny-416/variables, then run convert_tflite.py, it worked. @KLT1003