我正在尝试加载我的预训练模型 (yolov5n) 并在 PyTorch 中使用以下代码对其进行测试:
import os
import torch
model = torch.load(os.getcwd()+'/weights/last.pt')
# Images
imgs = ['https://example.com/img.jpg']
# Inference
results = model(imgs)
# Results
results.print()
results.save() # or .show()
results.xyxy[0] # img1 predictions (tensor)
results.pandas().xyxy[0] # img1 predictions (pandas)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
ModuleNotFoundError Traceback (最近一次调用最后) in 3 import torch 4 ----> 5 model = torch.load(os.getcwd()+'/weights/last.pt')
我的模型位于文件夹中/weights/last.py,我不确定我在做什么错误。你能告诉我,我的代码中缺少什么吗?