-1

I am trying to load a trained yolov5 model on a custom dataset using this:

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

but I am running into this error:

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)

Can anybody please tell what I'm doing wrong?

Vikas Kumar
  • 85
  • 1
  • 11
  • As an aside, you have asked 12 questions and marked 0 as accepted. This is fine if none of them answered your questions, but it also makes people hesitant to try to help and makes the questions resurface to the top of feed every few weeks or months. – JamesT Sep 21 '22 at 13:24

1 Answers1

1

From the Pytorch documentation website, it seems that the source option is set to github by default so your line of code:

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

actually means:

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

Thus, you need to set source=local as explained in the linked documentation, by keeping source='github' it means your programme is trying to find a GitHub repository (as can be seen in your error messages).

The fix is to use this line of code instead with the source set to local:

torch.hub.load('/home/yolov5/runs/train/yolo_sign_det2/weights', 'best', source='local')
JamesT
  • 117
  • 1
  • 3
  • 15
  • Hi James. I solved it by adding some additional parameters. Here's the code: `model = torch.hub.load(r'/home/yolov5', 'custom', path="path/to/the/best.pt", source='local') ` Thanks for your help! – Vikas Kumar Sep 23 '22 at 06:06
  • No problem, happy to help, if it answered your question then consider ticking it as answered please (it is the tick next to the vote buttons). Hope your ML is going well! – JamesT Sep 23 '22 at 11:35