前提・実現したいこと
ubuntu20.04
python3.8を使用しています。
現在、yolov5を動かしているのですが
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)
yolov5sモデルが以下の階層にある場合
yolov5
|ー yolov5s
model = torch.hub.load('~/yolov5', 'yolov5s', pretrained=True)
このようなイメージでパスを通したいと考えていますが実行できていません。
どうすれば、このような方法で通すことができますでしょうか。
申し訳ございませんがご教示いただけないでしょうか。
よろしくお願い致します。
エラー
Traceback (most recent call last): File "~/yolov5/pytorch_detect_realsense.py", line 61, in <module> main() File "~/yolov5/pytorch_detect_realsense.py", line 58, in main Y5.yolov5() File "~/yolov5/pytorch_detect_realsense.py", line 11, in yolov5 model = torch.hub.load('/home/limlab/yolov5', 'yolov5s.pt', pretrained=True) File "~/.local/lib/python3.8/site-packages/torch/hub.py", line 397, in load repo_or_dir = _get_cache_or_reload(repo_or_dir, force_reload, verbose, skip_validation) File "~/.local/lib/python3.8/site-packages/torch/hub.py", line 165, in _get_cache_or_reload repo_owner, repo_name, branch = _parse_repo_info(github) File "~/.local/lib/python3.8/site-packages/torch/hub.py", line 112, in _parse_repo_info repo_owner, repo_name = repo_info.split('/') ValueError: too many values to unpack (expected 2)
該当のソースコード
import torch import sys import pyrealsense2 as rs import numpy as np import cv2 import random import pickle as pkl class YOLOV5: def yolov5(self): model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True) color = (255,0,0) # ストリーム(Color/Depth)の設定 config = rs.config() config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30) config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30) # ストリーミング開始 pipeline = rs.pipeline() profile = pipeline.start(config) try: while True: # フレーム待ち frames = pipeline.wait_for_frames() #RGB RGB_frame = frames.get_color_frame() RGB_image = np.asanyarray(RGB_frame.get_data()) results = model(RGB_image) # 画像パスを設定し、物体検出を行う for *box, conf, cls in results.xyxy[0]: # xyxy, confidence, class #--- クラス名と信頼度を文字列変数に代入 #s = model.names[int(cls)]+":"+'{:.1f}'.format(float(conf)*100) s = model.names[int(cls)] if s == 'person': #--- 枠描画 cv2.rectangle(RGB_image,(int(box[0]), int(box[1])),(int(box[2]), int(box[3])),color,thickness=2,) #--- 文字枠と文字列描画 cv2.rectangle(RGB_image, (int(box[0]), int(box[1])-20), (int(box[0])+len(s)*10, int(box[1])), color, -1) cv2.putText(RGB_image, s, (int(box[0]), int(box[1])-5), cv2.FONT_HERSHEY_PLAIN, 1, [225,255,255], 1, cv2.LINE_AA) cv2.imshow('color',RGB_image) if cv2.waitKey(1) & 0xff == 27:#ESCで終了 cv2.destroyAllWindows() break finally: # ストリーミング停止 pipeline.stop() def main(): Y5 = YOLOV5() Y5.yolov5() if __name__ == '__main__': main()
def load(repo_or_dir, model, *args, source='github', force_reload=False, verbose=True, skip_validation=False, **kwargs): r""" Load a model from a github repo or a local directory. Note: Loading a model is the typical use case, but this can also be used to for loading other objects such as tokenizers, loss functions, etc. If ``source`` is 'github', ``repo_or_dir`` is expected to be of the form ``repo_owner/repo_name[:tag_name]`` with an optional tag/branch. If ``source`` is 'local', ``repo_or_dir`` is expected to be a path to a local directory. Args: repo_or_dir (string): If ``source`` is 'github', this should correspond to a github repo with format ``repo_owner/repo_name[:tag_name]`` with an optional tag/branch, for example 'pytorch/vision:0.10'. If ``tag_name`` is not specified, the default branch is assumed to be ``main`` if it exists, and otherwise ``master``. If ``source`` is 'local' then it should be a path to a local directory. model (string): the name of a callable (entrypoint) defined in the repo/dir's ``hubconf.py``. *args (optional): the corresponding args for callable ``model``. source (string, optional): 'github' or 'local'. Specifies how ``repo_or_dir`` is to be interpreted. Default is 'github'. force_reload (bool, optional): whether to force a fresh download of the github repo unconditionally. Does not have any effect if ``source = 'local'``. Default is ``False``. verbose (bool, optional): If ``False``, mute messages about hitting local caches. Note that the message about first download cannot be muted. Does not have any effect if ``source = 'local'``. Default is ``True``. skip_validation (bool, optional): if ``False``, torchhub will check that the branch or commit specified by the ``github`` argument properly belongs to the repo owner. This will make requests to the GitHub API; you can specify a non-default GitHub token by setting the ``GITHUB_TOKEN`` environment variable. Default is ``False``. **kwargs (optional): the corresponding kwargs for callable ``model``. Returns: The output of the ``model`` callable when called with the given ``*args`` and ``**kwargs``. Example: >>> # from a github repo >>> repo = 'pytorch/vision' >>> model = torch.hub.load(repo, 'resnet50', pretrained=True) >>> # from a local directory >>> path = '/some/local/path/pytorch/vision' >>> model = torch.hub.load(path, 'resnet50', pretrained=True) """ source = source.lower() if source not in ('github', 'local'): raise ValueError( f'Unknown source: "{source}". Allowed values: "github" | "local".') if source == 'github': repo_or_dir = _get_cache_or_reload(repo_or_dir, force_reload, verbose, skip_validation) model = _load_local(repo_or_dir, model, *args, **kwargs) return model
> 現在、yolov5を動かしているのですが
動かせる状態なのだから、
> このようなイメージでパスを通すことで実行できることは可能でしょうか。
実際やってみたら分かるのではないでしょうか

ご返信ありがとうございます。
質問の仕方が悪く申し訳ございません。
質問を編集します。
質問したいことですが、実際にその方法ではダメでしたのでそのようなイメージでできるようにするにはどのようにすればよいのでしょうか。ということをお聞きしたかったです。
ご教示いただけないでしょうか。
よろしくお願い致します。
