TexasInstruments / edgeai-yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite. Forked from https://ultralytics.com/yolov5

Home Page:https://github.com/TexasInstruments/edgeai

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

detect.py error: AttributeError: 'Focus' object has no attribute 'conv_slice'

HawkDukez opened this issue · comments

❔Question

I tried to use

      python detect.py --weights ../last.pt --source ../pose-datasets/val

to detect my own images. I got this message

Traceback (most recent call last):
File "detect.py", line 238, in
main(opt)
File "detect.py", line 233, in main
run(**vars(opt))
File "/data/cv/visual_team1/pengyu.zou/anaconda3/envs/pose/lib/python3.7/site-packages/torch/autograd/grad_mode.py", line 28, in decorate_context
return func(*args, **kwargs)
File "detect.py", line 98, in run
model(torch.zeros(1, 3, imgsz, imgsz).to(device).type_as(next(model.parameters()))) # run once
File "/data/cv/visual_team1/pengyu.zou/anaconda3/envs/pose/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
return forward_call(*input, **kwargs)
File "/data/cv/visual_team1/pengyu.zou/edgeai-yolov5/models/yolo.py", line 122, in forward
return self.forward_once(x, profile, visualize) # single-scale inference, train
File "/data/cv/visual_team1/pengyu.zou/edgeai-yolov5/models/yolo.py", line 153, in forward_once
x = m(x) # run
File "/data/cv/visual_team1/pengyu.zou/anaconda3/envs/pose/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
return forward_call(*input, **kwargs)
File "/data/cv/visual_team1/pengyu.zou/edgeai-yolov5/models/common.py", line 184, in forward
x = self.conv_slice(x)
File "/data/cv/visual_team1/pengyu.zou/anaconda3/envs/pose/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1131, in getattr
type(self).name, name))
AttributeError: 'Focus' object has no attribute 'conv_slice'

I've checked the code in common.py and seen no wrong:

class Focus(nn.Module):
def init(self, c1, c2, k=1, s=1, p=None, g=1, act=True): # ch_in, ch_out, kernel, stride, padding, groups
super(Focus, self).init()
slice_kernel = 3
slice_stride = 2
self.conv_slice = Conv(c1, c1*4, slice_kernel, slice_stride, p, g, act)
self.conv = Conv(c1 * 4, c2, k, s, p, g, act)
# self.contract = Contract(gain=2)

def forward(self, x):  # x(b,c,w,h) -> y(b,4c,w/2,h/2)
    #return self.conv(torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1))
    #replace slice operations with conv
    x = self.conv_slice(x)
    x = self.conv(x)
    return x
    # return self.conv(self.contract(x))

Does anyone know how to solve this?

FYI, I clone the code from master branch

switch to yolo-pose branch and it's solved