怎样将YOLOv5部署到移动端 报错:name ‘SPPF‘ is not defined

问题描述:
ultralytics发布的yolov5 6.0版本中已经加入了export.py文件可以将训练好的模型.pt转换为.tflite格式的轻量化模型部署在Android端,但是注意6.0版本当前代码只能转换5.0版本的。
我在使用6.0版本的export.py代码时报错 name ‘SPPF’ is not defined,找了半天报错的位置才发现,6.0版本模型文件中model/commen.py文件夹中多了一个SPPF模块来代替5.0版本中的SPP模块,当然旧的SPP模块依旧还在,而在将模型转换为tensorflow模型时,export.py(还没随之更新)只能识别SPP模块,而不能识别SPPF模块导致的。
解释:下面这行代码就是export.py调用的,他并没有考虑SPPF这个模块。
在这里插入图片描述

解决方法:
将5.0版本的模型配置文件yolov5s.yaml移到6.0版本中的model文件夹下,训练一版模型后,然后实际上利用6.0版本的export.py来生成5.0版本的模型对应的.tflite文件。
接下来就参照这些部署就好了:

2. Convert and verify

  • Convert weights to fp16 TFLite model, and verify it with
python export.py --weights yolov5s.pt --include tflite --img 320
python detect.py --weights yolov5s-fp16.tflite --img 320

or

  • Convert weights to int8 TFLite model, and verify it with
python export.py --weights yolov5s.pt --include tflite --int8 --img 320 --data data/coco128.yaml
python detect.py --weights yolov5s-int8.tflite --img 320

Note that:

  • int8 quantization needs dataset images to calibrate weights and activations, and the default COCO128 dataset is downloaded automatically.
  • Change --img to the input resolution of your model, if it isn’t 320.

3. Clone this repo (tf-android branch) for Android app

git clone https://github.com/zldrobit/yolov5.git yolov5-android

4. Put TFLite models in assets folder of Android project, and change

  • inputSize to --img
  • output_width according to new/old inputSize ratio
  • anchors to m.anchor_grid as https://github.com/ultralytics/yolov5/pull/1127#issuecomment-714651073
    in android/app/src/main/java/org/tensorflow/lite/examples/detection/tflite/DetectorFactory.java
  • labelFilename according to the classes of the model
    in https://github.com/zldrobit/yolov5/blob/522d65e848d3e5a378eb0f29a9fbb204221400e8/android/app/src/main/java/org/tensorflow/lite/examples/detection/tflite/DetectorFactory.java#L19-L48.

Then run the program in Android Studio.

参照博客:

大佬示范链接

  • 15
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
问题: yolov5训练时报错,如何解决? 回答: 在yolov5训练过程中,可能会遇到不同的错误。根据引用\[1\]和引用\[2\]的内容,有几种常见的错误和解决方法。首先,如果在训练开始时出现AttributeError: Can't get attribute 'SPPF'错误,可以尝试使用正确的解决方法来解决这个问题。其次,如果在运行yolov5-5.0时出现RuntimeError: result type Float can't be cast to the desired output type__int64错误,可以尝试检查代码中的数据类型是否正确。此外,如果在初次编译时出现ModuleNotFoundError: No module named 'torch'错误,可以尝试安装缺少的torch模块。总之,根据具体的错误信息,可以参考引用\[2\]中提供的链接,或者根据引用\[3\]中的汇总来解决yolov5训练时的报错。 #### 引用[.reference_title] - *1* [YOLOv5训练遇到的问题(上)](https://blog.csdn.net/sinat_38961618/article/details/124769585)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [YOLOv5初级问题与报错汇总](https://blog.csdn.net/m0_68524176/article/details/128415084)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值