1

When I try to convert yolov4 weights to tflite, ValueError has occurred. I can't solve this problem and find an appropriate answer. This weights file is available in the PycharmProject .py file, and I can find it perform in an object detection code. But in the process of converting to tflite, ValueError has occurred.



Used GitHub link : tensorflow_yolov4_tflite tensorflow-yolov4

I referenced this StackOverflow Q&A, but it doesn't work. Unable to convert YOLOv4 to tflite



This is ErrorCode.

(convert_tflite.py and convert.py (to pb) are also doesn't work.)

C:\Users\HANSUHO\GitClone\totflite>python save_model.py --weights ./data/clothes_yolov4-custom_final.weights --output ./checkpoints/yolov4-416 --input_size 416 --model yolov4 --framework tflite

2020-09-22 16:29:38.010283: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-09-22 16:29:38.036873: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2020-09-22 16:29:44.344951: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2020-09-22 16:29:44.360513: W tensorflow/stream_executor/cuda/cuda_driver.cc:312] failed call to cuInit: UNKNOWN ERROR (303)
2020-09-22 16:29:44.379603: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: DESKTOP-S931GV6
2020-09-22 16:29:44.393095: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: DESKTOP-S931GV6
2020-09-22 16:29:44.402485: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations:  AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2020-09-22 16:29:44.453636: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x26a5376f020 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-09-22 16:29:44.475123: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
Traceback (most recent call last):
  File "save_model.py", line 58, in <module>
    app.run(main)
  File "C:\Users\HANSUHO\AppData\Local\Programs\Python\Python37\lib\site-packages\absl\app.py", line 300, in run
    _run_main(main, args)
  File "C:\Users\HANSUHO\AppData\Local\Programs\Python\Python37\lib\site-packages\absl\app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "save_model.py", line 54, in main
    save_tf()
  File "save_model.py", line 49, in save_tf
    utils.load_weights(model, FLAGS.weights, FLAGS.model, FLAGS.tiny)
  File "C:\Users\HANSUHO\GitClone\totflite\core\utils.py", line 63, in load_weights
    conv_weights = conv_weights.reshape(conv_shape).transpose([2, 3, 1, 0])
ValueError: cannot reshape array of size 4565322 into shape (1024,512,3,3)
Suho Han
  • 11
  • 4

2 Answers2

0

Will you check the input/output size? the size of 4565322 and (1024,512,3,3) are different.

Taehee Jeong
  • 146
  • 2
  • Yes, I was check the input/output size. Before the training for custom weights, cfg.txt file's input size is 416 and convert_tflite.py 's size also same.. But I don't know why this error was occured, and what is different [size of 4565322 and (1024,512,3,3)] .. – Suho Han Sep 24 '20 at 05:34
0

https://github.com/hunglc007/tensorflow-yolov4-tflite/issues/147#issuecomment-666736983

check this, it will solve the issue.

Basically, you are cloning the root repo to run this file while having the paths in core/config.py unchanged.