20230424
python3.7中报错:No module named ‘typing_extensions‘
在网上找到的解决办法:【pytorch】错误:No module named ‘typing_extensions‘ 问题解决_no module named typing_污喵王z的博客-CSDN博客
就是将缺失的文件typing_extensions.py,补充到路径:…\envs\py3.7\Lib\typing.py的同目录下,但发现github上的文件丢失,这里附上新路径1:typing_extensions/typing_extensions.py at main · python/typing_extensions · GitHub
路径2:(300条消息) python3.7报错:typing-extensions.py文件按丢失资源-CSDN文库
20230306
复现Github:
GitHub - Sharpiless/Yolov5-Flask-VUE: 基于Flask开发后端、VUE开发前端框架,在WEB端部署YOLOv5目标检测模型
运行时报错:
RuntimeError: "slow_conv2d_cpu" not implemented for 'Half'
整体情况:
在执行F.conv2d(input, weight, bias, self.stride, self.padding, self.dilation, self.groups)这句代码的时候报的错误。
报错情况:
Traceback (most recent call last):
File "D:\SOFTWARE\ProgrammeSoftware\Programs\Python\Python39\lib\site-packages\flask\app.py", line 2551, in __call__
return self.wsgi_app(environ, start_response)
File "D:\SOFTWARE\ProgrammeSoftware\Programs\Python\Python39\lib\site-packages\flask\app.py", line 2531, in wsgi_app
response = self.handle_exception(e)
File "D:\SOFTWARE\ProgrammeSoftware\Programs\Python\Python39\lib\site-packages\flask\app.py", line 2528, in wsgi_app
response = self.full_dispatch_request()
File "D:\SOFTWARE\ProgrammeSoftware\Programs\Python\Python39\lib\site-packages\flask\app.py", line 1825, in full_dispatch_request
rv = self.handle_user_exception(e)
File "D:\SOFTWARE\ProgrammeSoftware\Programs\Python\Python39\lib\site-packages\flask\app.py", line 1823, in full_dispatch_request
rv = self.dispatch_request()
File "D:\SOFTWARE\ProgrammeSoftware\Programs\Python\Python39\lib\site-packages\flask\app.py", line 1799, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File "E:\WorkSpace\ProjectPrograme\Python\Yolov5-Flask-VUE\back-end\app.py", line 53, in upload_file
pid, image_info = core.main.c_main(
File "E:\WorkSpace\ProjectPrograme\Python\Yolov5-Flask-VUE\back-end\core\main.py", line 6, in c_main
image_info = predict.predict(image_data, model, ext)
File "E:\WorkSpace\ProjectPrograme\Python\Yolov5-Flask-VUE\back-end\core\predict.py", line 10, in predict
img_y, image_info = model.detect(x)
File "E:\WorkSpace\ProjectPrograme\Python\Yolov5-Flask-VUE\back-end\processor\AIDetector_pytorch.py", line 70, in detect
pred = self.m(img, augment=False)[0]
File "D:\SOFTWARE\ProgrammeSoftware\Programs\Python\Python39\lib\site-packages\torch\nn\modules\module.py", line 1194, in _call_impl
return forward_call(*input, **kwargs)
File "E:\WorkSpace\ProjectPrograme\Python\Yolov5-Flask-VUE\back-end\models\yolo.py", line 112, in forward
return self.forward_once(x, profile) # single-scale inference, train
File "E:\WorkSpace\ProjectPrograme\Python\Yolov5-Flask-VUE\back-end\models\yolo.py", line 128, in forward_once
x = m(x) # run
File "D:\SOFTWARE\ProgrammeSoftware\Programs\Python\Python39\lib\site-packages\torch\nn\modules\module.py", line 1194, in _call_impl
return forward_call(*input, **kwargs)
File "E:\WorkSpace\ProjectPrograme\Python\Yolov5-Flask-VUE\back-end\models\common.py", line 90, in forward
return self.conv(torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1))
File "D:\SOFTWARE\ProgrammeSoftware\Programs\Python\Python39\lib\site-packages\torch\nn\modules\module.py", line 1194, in _call_impl
return forward_call(*input, **kwargs)
File "E:\WorkSpace\ProjectPrograme\Python\Yolov5-Flask-VUE\back-end\models\common.py", line 34, in fuseforward
return self.act(self.conv(x))
File "D:\SOFTWARE\ProgrammeSoftware\Programs\Python\Python39\lib\site-packages\torch\nn\modules\module.py", line 1194, in _call_impl
return forward_call(*input, **kwargs)
File "D:\SOFTWARE\ProgrammeSoftware\Programs\Python\Python39\lib\site-packages\torch\nn\modules\conv.py", line 463, in forward
return self._conv_forward(input, self.weight, self.bias)
File "D:\SOFTWARE\ProgrammeSoftware\Programs\Python\Python39\lib\site-packages\torch\nn\modules\conv.py", line 459, in _conv_forward
return F.conv2d(input, weight, bias, self.stride,
RuntimeError: "slow_conv2d_cpu" not implemented for 'Half'
然后根据错误,找到了这篇博客:RuntimeError: “unfolded2d_copy“ not implemented for ‘Half‘(实测百分百有效)_醉公子~的博客-CSDN博客
刚开始没动只改一句:
model.float()导致输入输出的结果不一样又报错: RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor)
然后通过ctrl+shift+r继续查找:
找到了三处需要将half()改为float()的地方,并将其一一修改。
修改完后,继续运行,不出意外
又报错:AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'
发现是upsampling.py文件中,存在了recompute_scale_factor参数冗余。
解决方案就是对Upsample.py进行修改
(256条消息) YOLOV5 | AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘ 问题解决 亲测有效_RodgeH的博客-CSDN博客
最后的最后,上述错误都解决了。
又来了个文件存储的错误:
Exception: 保存图片时出错.Error saving thepicture.
这是正常的...代码写错
参考:
【目标检测】Flask+Docker在服务器部署YOLOv5应用 - 腾讯云开发者社区-腾讯云
安全验证 - 知乎
AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘_知道的都知道 不知道的慢慢了解的博客-CSDN博客