pytorch ValueError:尝试加载yolov5模型时要解包的值太多(应为2个)

ix0qys7i  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(308)

我正在尝试使用以下代码在自定义数据集上加载经过训练的yolov5模型:


# Model

model = torch.hub.load('/home/yolov5/runs/train/yolo_sign_det2/weights', 'best')  # or yolov5n - yolov5x6, custom

但是我遇到了这个错误:

ValueError                                Traceback (most recent call last)
<ipython-input-3-c832ab8c1eab> in <module>
      2 
      3 # Model
----> 4 model = torch.hub.load('/home/yolov5/runs/train/yolo_sign_det2/weights', 'best')  # or yolov5n - yolov5x6, custom
      5 
      6 # Images

~/.conda/envs/yolo/lib/python3.6/site-packages/torch/hub.py in load(repo_or_dir, model, source, force_reload, verbose, skip_validation, *args,**kwargs)
    395 
    396     if source == 'github':
--> 397         repo_or_dir = _get_cache_or_reload(repo_or_dir, force_reload, verbose, skip_validation)
    398 
    399     model = _load_local(repo_or_dir, model, *args,**kwargs)

~/.conda/envs/yolo/lib/python3.6/site-packages/torch/hub.py in _get_cache_or_reload(github, force_reload, verbose, skip_validation)
    163         os.makedirs(hub_dir)
    164     # Parse github repo information
--> 165     repo_owner, repo_name, branch = _parse_repo_info(github)
    166     # Github allows branch name with slash '/',
    167     # this causes confusion with path on both Linux and Windows.

~/.conda/envs/yolo/lib/python3.6/site-packages/torch/hub.py in _parse_repo_info(github)
    110     else:
    111         repo_info, branch = github, None
--> 112     repo_owner, repo_name = repo_info.split('/')
    113 
    114     if branch is None:

ValueError: too many values to unpack (expected 2)

谁能告诉我我哪里做错了吗?

6rqinv9w

6rqinv9w1#

Pytorch documentation website中,source选项似乎默认设置为github,因此您的代码行:

model = torch.hub.load('/home/yolov5/runs/train/yolo_sign_det2/weights', 'best')  # or yolov5n - yolov5x6, custom

实际上是指:

model = torch.hub.load('/home/yolov5/runs/train/yolo_sign_det2/weights', 'best', source='github')  # or yolov5n - yolov5x6, custom

因此,您需要按照链接文档中的说明设置source=local,保持source='github'意味着您的程序正在尝试查找一个GitHub仓库(如您的错误消息所示)。
修复方法是将source设置为local,然后使用以下代码行:

torch.hub.load('/home/yolov5/runs/train/yolo_sign_det2/weights', 'best', source='local')

相关问题