【问题标题】:How can I solve reshape ValueError when convert yolov4 weights to tflite?将yolov4权重转换为tflite时如何解决reshape ValueError?
【发布时间】:2020-09-22 08:04:37
【问题描述】:

当我尝试将 yolov4 权重转换为 tflite 时,发生了 ValueError。我无法解决这个问题并找到合适的答案。 这个权重文件在 PycharmProject .py 文件中可用,我可以在对象检测代码中找到它。 但是在转换为tflite的过程中,出现了ValueError。



使用的 GitHub 链接: tensorflow_yolov4_tflite tensorflow-yolov4

我参考了这个 StackOverflow Q&A,但它不起作用。 Unable to convert YOLOv4 to tflite



这是错误代码。

(convert_tflite.py 和 convert.py (to pb) 也不起作用。)

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 --框架 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)

【问题讨论】:

  • 我认为gpu已经耗尽。
  • 我的笔记本电脑上没有 GPU。它需要 GPU 吗?
  • 我不确定。但一般不会。你用的是哪个tf?为什么一开始会触发搜索你的gpu?
  • 我笔记本的tf版本是2.3。感谢您的评论,我猜这个问题可能是因为 gpu 造成的,/所以我正在 google colab 上尝试这个问题。
  • 在colab中,出现同样的错误...m..

标签: python object-detection converters yolo tensorflow-lite


【解决方案1】:

您会检查输入/输出大小吗? 4565322和(1024,512,3,3)的大小不同。

【讨论】:

  • 是的,我正在检查输入/输出大小。在训练自定义权重之前,cfg.txt 文件的输入大小是 416 和 convert_tflite.py 的大小也一样.. 但是我不知道为什么会发生这个错误,有什么不同 [size of 4565322 and (1024, 512,3,3)] ..
【解决方案2】:

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

检查一下,它会解决问题。

基本上,您正在克隆根存储库以运行此文件,同时保持 core/config.py 中的路径不变。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-23
    • 1970-01-01
    • 1970-01-01
    • 2021-04-09
    • 1970-01-01
    • 2019-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多