python - 将yolov4权重转换为tflite时如何解决reshape ValueError?
问题描述
当我尝试将 yolov4 权重转换为 tflite 时,发生了 ValueError。我无法解决这个问题并找到合适的答案。这个权重文件在 PycharmProject .py 文件中可用,我可以在对象检测代码中找到它。但是在转换为tflite的过程中,出现了ValueError。
使用的 GitHub 链接: tensorflow_yolov4_tflite tensorflow-yolov4
我引用了这个 StackOverflow Q&A,但它不起作用。 无法将 YOLOv4 转换为 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 --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)
解决方案
https://github.com/hunglc007/tensorflow-yolov4-tflite/issues/147#issuecomment-666736983
检查一下,它将解决问题。
基本上,您正在克隆根存储库以运行此文件,同时保持 core/config.py 中的路径不变。
推荐阅读
- java - Java 分数基转换
- python - 试图过滤类别列中具有“餐厅”的行
- visual-studio-code - 带有分层大纲、DocumentSymbol 的 VSCode 语言扩展
- soap - 如何从 Dynamics 365 按 ID 获取 >130 个实体的列表?
- sql - R dbWriteTable 不适用于所有 NA 的列和不合逻辑的类
- python - 如何使算法对字符串变量进行自动转换?
- angular - 用作 PartialObserver 的 BehaviorSubject 中断了对 BehaviorSubject 的订阅
- java - 为什么检测 Spring REST Controller 线程等待锁定?
- r - 使用准引号命名新列时可以使用函数吗?
- asp.net-mvc - 具有分组功能的 Kendo Grid 自动跳转到第一个匹配元素