小编Moh*_*hny的帖子

如何在pytorch中加载自定义模型

我正在尝试加载我的预训练模型 (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,我不确定我在做什么错误。你能告诉我,我的代码中缺少什么吗?

python pytorch yolo yolov5

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

python ×1

pytorch ×1

yolo ×1

yolov5 ×1