当前位置:网站首页>AttributeError: Can't get attribute 'SPPF' on
AttributeError: Can't get attribute 'SPPF' on
2022-08-02 03:32:00
【woshicaiji12138】
错误信息:
Namespace(augment=False, batch_size=32, conf_thres=0.001, data=‘/yolov5-5.0/data/coco128.yaml’, device=‘’, exist_ok=False, img_size=640, iou_thres=0.6, name=‘exp’, project=‘runs/test’, save_conf=False, save_hybrid=False, save_json=False, save_txt=False, single_cls=False, task=‘val’, verbose=False, weights=[‘/yolov5-5.0/weights/yolov5s.pt’])
YOLOv5 2021-4-11 torch 1.10.1+cu111 CUDA:0 (NVIDIA GeForce RTX 3090, 24268.3125MB)
Traceback (most recent call last):
File “/yolov5-5.0/test.py”, line 313, in
test(opt.data,
File “/yolov5-5.0/test.py”, line 56, in test
model = attempt_load(weights, map_location=device) # load FP32 model
File “/yolov5-5.0/models/experimental.py”, line 118, in attempt_load
ckpt = torch.load(w, map_location=map_location) # load
File “/opt/conda/lib/python3.8/site-packages/torch/serialization.py”, line 607, in load
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
File “/opt/conda/lib/python3.8/site-packages/torch/serialization.py”, line 882, in _load
result = unpickler.load()
File “/opt/conda/lib/python3.8/site-packages/torch/serialization.py”, line 875, in find_class
return super().find_class(mod_name, name)
AttributeError: Can’t get attribute ‘SPPF’ on <module ‘models.common’ from ‘/yolov5-5.0/models/common.py’>
方法一:
改正方法,在models/common.py中增加一个类:
import warnings
class SPPF(nn.Module):
# Spatial Pyramid Pooling - Fast (SPPF) layer for YOLOv5 by Glenn Jocher
def __init__(self, c1, c2, k=5): # equivalent to SPP(k=(5, 9, 13))
super().__init__()
c_ = c1 // 2 # hidden channels
self.cv1 = Conv(c1, c_, 1, 1)
self.cv2 = Conv(c_ * 4, c2, 1, 1)
self.m = nn.MaxPool2d(kernel_size=k, stride=1, padding=k // 2)
def forward(self, x):
x = self.cv1(x)
with warnings.catch_warnings():
warnings.simplefilter('ignore') # suppress torch 1.9.0 max_pool2d() warning
y1 = self.m(x)
y2 = self.m(y1)
return self.cv2(torch.cat([x, y1, y2, self.m(y2)], 1))
方法二:检查自己下载的yolov5s.ptWhether the model is consistent with the version of the code you use.
2022-08-02 03:32:00 【woshicaiji12138】
错误信息:
Namespace(augment=False, batch_size=32, conf_thres=0.001, data=‘/yolov5-5.0/data/coco128.yaml’, device=‘’, exist_ok=False, img_size=640, iou_thres=0.6, name=‘exp’, project=‘runs/test’, save_conf=False, save_hybrid=False, save_json=False, save_txt=False, single_cls=False, task=‘val’, verbose=False, weights=[‘/yolov5-5.0/weights/yolov5s.pt’])
YOLOv5 2021-4-11 torch 1.10.1+cu111 CUDA:0 (NVIDIA GeForce RTX 3090, 24268.3125MB)
Traceback (most recent call last):
File “/yolov5-5.0/test.py”, line 313, in
test(opt.data,
File “/yolov5-5.0/test.py”, line 56, in test
model = attempt_load(weights, map_location=device) # load FP32 model
File “/yolov5-5.0/models/experimental.py”, line 118, in attempt_load
ckpt = torch.load(w, map_location=map_location) # load
File “/opt/conda/lib/python3.8/site-packages/torch/serialization.py”, line 607, in load
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
File “/opt/conda/lib/python3.8/site-packages/torch/serialization.py”, line 882, in _load
result = unpickler.load()
File “/opt/conda/lib/python3.8/site-packages/torch/serialization.py”, line 875, in find_class
return super().find_class(mod_name, name)
AttributeError: Can’t get attribute ‘SPPF’ on <module ‘models.common’ from ‘/yolov5-5.0/models/common.py’>
方法一:
改正方法,在models/common.py中增加一个类:
import warnings
class SPPF(nn.Module):
# Spatial Pyramid Pooling - Fast (SPPF) layer for YOLOv5 by Glenn Jocher
def __init__(self, c1, c2, k=5): # equivalent to SPP(k=(5, 9, 13))
super().__init__()
c_ = c1 // 2 # hidden channels
self.cv1 = Conv(c1, c_, 1, 1)
self.cv2 = Conv(c_ * 4, c2, 1, 1)
self.m = nn.MaxPool2d(kernel_size=k, stride=1, padding=k // 2)
def forward(self, x):
x = self.cv1(x)
with warnings.catch_warnings():
warnings.simplefilter('ignore') # suppress torch 1.9.0 max_pool2d() warning
y1 = self.m(x)
y2 = self.m(y1)
return self.cv2(torch.cat([x, y1, y2, self.m(y2)], 1))
方法二:检查自己下载的yolov5s.ptWhether the model is consistent with the version of the code you use.
边栏推荐
- JVM学习----垃圾回收--G1
- LeetCode:1374. 生成每种字符都是奇数个的字符串【签到题】
- Keil development environment installation tutorial
- SSM整合
- Using WebShell to get Shell Skills
- 2022.7.30 js notes Operators and flow controllers, loops
- 腾讯50题
- MySQL常见的索引
- [Remote Control Development Basic Tutorial 3] Crazy Shell Open Source Formation UAV-ADC (Joystick Control)
- Redis笔记基础篇:6分钟看完Redis的八种数据类型
猜你喜欢
随机推荐
5. Hezhou Air32F103_LCD_key
HCIP第十一天_MPLS实验
AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘
网站与服务器维护怎么做?
@Configuration详解
Debian 10 NTP 服务配置
MySQL8.0与MySQL5.7差异分析
2022.7.30 js笔记 运算符和流程控制符、循环
MySQL中的各种锁(行锁、间隙锁、临键锁等等LBCC)
RHCSA第三天
@Autowired详解[email protected]在static属性上的使用
MySQL中字符串比较大小(日期字符串比较问题)
MySQL删除表数据 MySQL清空表命令 3种方法
磷脂-聚乙二醇-巯基,DSPE-PEG-Thiol,DSPE-PEG-SH,MW:5000
Chapter 10 聚类
线性代数学习笔记3-3:逆矩阵的理解
线性代数学习笔记2-2:向量空间、子空间、最大无关组、基、秩与空间维数
构造方法、方法重载、全局变量与局部变量
【博学谷学习记录】超强总结,用心分享 | 软件测试 接口测试基础
JVM学习----垃圾回收--G1









