0

Hello I am trying to load yolo7-w6-pose.pt model in a separate project, in order to do this I start with the following code:

path = 'yolov7-w6-pose.pt'
model = torch.hub.load("WongKinYiu/yolov7","custom",f"{path}",trust_repo=True)

This code returns the following error:

    219 self.no_det=(nc + 5)  # number of outputs per anchor for box and class
    220 self.no_kpt = 3*self.nkpt ## number of outputs per anchor for keypoints
--> 221 self.no = self.no_det+self.no_kpt
    222 self.nl = len(anchors)  # number of detection layers
    223 self.na = len(anchors[0]) // 2  # number of anchors

TypeError: unsupported operand type(s) for +: 'int' and 'str'

After this I tried with restart the kernel and this code:

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
path = 'yolov7-w6-pose.pt'
#model = torch.hub.load("WongKinYiu/yolov7","custom",f"{path}",trust_repo=True)
weigths = torch.load(f"{path}")
model = weigths['model']
_ = model.float().eval()

if torch.cuda.is_available():
    model.half().to(device)

but this return this error:

ModuleNotFoundError: No module named 'models'

because I don't have the models folder from the origin repository and I don't want to copy that folder into my current project.

Anyway if I restart the kernel again and I run the first piece of the code, and after that, I execute the second piece of the code, the model works, but I am not sure how, and I don't like put an extra try catch only to allow that the first code can fail in order to load a model.

Can I solve this and load the model clearly? why is failing? is there any way to fix this?

Thanks.

Tlaloc-ES
  • 4,825
  • 7
  • 38
  • 84

0 Answers0