当前位置:网站首页>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.
边栏推荐
猜你喜欢
随机推荐
(Reposted) The relationship between hashcode and equals
Brute force visitors
@Configuration详解
5.nodejs--cross domain, CORS, JSONP, Proxy
RHCSA第三天
线性代数学习笔记1:何为线性代数
LeetCode:第304场周赛【总结】
Day34 LeetCode
弹性盒子flex属性
小程序(开发必备常识)1
Redis简单学习笔记
DOM破坏及复现实验
LeetCode:1374. 生成每种字符都是奇数个的字符串【签到题】
DSPE-PEG-PDP,DSPE-PEG-OPSS,磷脂-聚乙二醇-巯基吡啶供应,MW:5000
MySQL分页查询的5种方法
parser = argparse.ArgumentParser()解析
关于跨域问题
连接数据库时遇到的bug1号
About cross-domain issues
subprocess.CalledProcessError: Command ‘pip install ‘thop‘‘ returned non-zero exit status 1.