ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.73k stars 16.34k forks source link

[solve]Exception: path is on mount 'C:', start on mount 'D:'. Cache may be out of date, #6976

Closed polarbear0827 closed 2 years ago

polarbear0827 commented 2 years ago

Search before asking

YOLOv5 Component

Detection

Bug

D:\Users\a5201\yolococogpu01\venv\Scripts\python.exe D:/Users/a5201/yolococogpu01/detect01.py Downloading: "https://github.com/ultralytics/yolov5/archive/master.zip" to C:\Users\USER/.cache\torch\hub\master.zip fatal: not a git repository (or any of the parent directories): .git YOLOv5 2022-3-14 torch 1.8.2+cu111 CUDA:0 (NVIDIA GeForce GTX 950M, 2048MiB)

Traceback (most recent call last): File "C:\Users\USER/.cache\torch\hub\ultralytics_yolov5_master\hubconf.py", line 46, in _create model = DetectMultiBackend(path, device=device) # download/load FP32 model File "C:\Users\USER/.cache\torch\hub\ultralytics_yolov5_master\models\common.py", line 297, in init pt, jit, onnx, xml, engine, coreml, saved_model, pb, tflite, edgetpu, tfjs = self.model_type(w) # get backend File "C:\Users\USER/.cache\torch\hub\ultralytics_yolov5_master\models\common.py", line 475, in model_type from export import export_formats File "C:\Users\USER/.cache\torch\hub\ultralytics_yolov5_master\export.py", line 64, in ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\ntpath.py", line 703, in relpath raise ValueError("path is on mount %r, start on mount %r" % ( ValueError: path is on mount 'C:', start on mount 'D:'

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "D:\Users\a5201\yolococogpu01\detect01.py", line 5, in model = torch.hub.load("ultralytics/yolov5", "custom", path = "yolov5/runs/train/exp34/weights/best.pt", force_reload=True ).autoshape() File "D:\Users\a5201\yolococogpu01\venv\lib\site-packages\torch\hub.py", line 339, in load model = _load_local(repo_or_dir, model, *args, *kwargs) File "D:\Users\a5201\yolococogpu01\venv\lib\site-packages\torch\hub.py", line 368, in _load_local model = entry(args, **kwargs) File "C:\Users\USER/.cache\torch\hub\ultralytics_yolov5_master\hubconf.py", line 70, in custom return _create(path, autoshape=autoshape, verbose=verbose, device=device) File "C:\Users\USER/.cache\torch\hub\ultralytics_yolov5_master\hubconf.py", line 65, in _create raise Exception(s) from e Exception: path is on mount 'C:', start on mount 'D:'. Cache may be out of date, try force_reload=True or see https://github.com/ultralytics/yolov5/issues/36 for help.

Process finished with exit code 1

Environment

YOLOv5 2022-3-14 torch 1.8.2+cu111 CUDA:0 (NVIDIA GeForce GTX 950M, 2048MiB) Python3.9

Minimal Reproducible Example

No response

Additional

code: import torch import cv2 import numpy as np

model = torch.hub.load("ultralytics/yolov5", "custom", path = "yolov5/runs/train/exp34/weights/best.pt", force_reload=True )

Are you willing to submit a PR?

github-actions[bot] commented 2 years ago

👋 Hello @polarbear0827, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email support@ultralytics.com.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

quangdungluong commented 2 years ago

I have the same problem as you. The possible reason for this error is the os.relpath does not give you a relative path between two directories. I tried load model by clone the repo and load local and it works. model = torch.hub.load(path/to/yolov5, 'custom', path=path/to/your/model ,source='local') You also avoid this problem by copying your app to C: drive, selecting your python interpreter and trying to execute the code again.

polarbear0827 commented 2 years ago

Is it changed to this?

model = torch.hub.load("C:/Users/USER/.cache/torch/hub/ultralytics_yolov5_master", "custom", path = "D:/Users/a5201/olococogpu01/yolov5/runs/train/exp34/weights/best.pt", force_reload=True )

polarbear0827 commented 2 years ago

it produces another error

D:\Users\a5201\yolococogpu01\venv\Scripts\python.exe D:/Users/a5201/yolococogpu01/detect01.py Traceback (most recent call last): File "D:\Users\a5201\yolococogpu01\detect01.py", line 5, in model = torch.hub.load("C:/Users/USER/.cache/torch/hub/ultralytics_yolov5_master", "custom", path = "D:/Users/a5201/olococogpu01/yolov5/runs/train/exp34/weights/best.pt", force_reload=True ) File "D:\Users\a5201\yolococogpu01\venv\lib\site-packages\torch\hub.py", line 337, in load repo_or_dir = _get_cache_or_reload(repo_or_dir, force_reload, verbose) File "D:\Users\a5201\yolococogpu01\venv\lib\site-packages\torch\hub.py", line 121, in _get_cache_or_reload repo_owner, repo_name, branch = _parse_repo_info(github) File "D:\Users\a5201\yolococogpu01\venv\lib\site-packages\torch\hub.py", line 111, in _parse_repo_info repo_owner, repo_name = repo_info.split('/') ValueError: not enough values to unpack (expected 2, got 1)

quangdungluong commented 2 years ago

Is it changed to this?

model = torch.hub.load("C:/Users/USER/.cache/torch/hub/ultralytics_yolov5_master", "custom", path = "D:/Users/a5201/olococogpu01/yolov5/runs/train/exp34/weights/best.pt", force_reload=True )

I haven't tried it. I cloned yolov5 repo and it works.

quangdungluong commented 2 years ago

it produces another error

D:\Users\a5201\yolococogpu01\venv\Scripts\python.exe D:/Users/a5201/yolococogpu01/detect01.py

Traceback (most recent call last):

File "D:\Users\a5201\yolococogpu01\detect01.py", line 5, in

model = torch.hub.load("C:/Users/USER/.cache/torch/hub/ultralytics_yolov5_master", "custom", path = "D:/Users/a5201/olococogpu01/yolov5/runs/train/exp34/weights/best.pt", force_reload=True )

File "D:\Users\a5201\yolococogpu01\venv\lib\site-packages\torch\hub.py", line 337, in load

repo_or_dir = _get_cache_or_reload(repo_or_dir, force_reload, verbose)

File "D:\Users\a5201\yolococogpu01\venv\lib\site-packages\torch\hub.py", line 121, in _get_cache_or_reload

repo_owner, repo_name, branch = _parse_repo_info(github)

File "D:\Users\a5201\yolococogpu01\venv\lib\site-packages\torch\hub.py", line 111, in _parse_repo_info

repo_owner, repo_name = repo_info.split('/')

ValueError: not enough values to unpack (expected 2, got 1)

remember "source=local"

polarbear0827 commented 2 years ago

i'd like to apologize for my forgot that, but it still error

model = torch.hub.load("C:/Users/USER/.cache/torch/hub/ultralytics_yolov5_master", "custom", path = "D:/Users/a5201/olococogpu01/yolov5/runs/train/exp34/weights/best.pt", source='local' )

fatal: not a git repository (or any of the parent directories): .git YOLOv5 2022-3-14 torch 1.8.2+cu111 CUDA:0 (NVIDIA GeForce GTX 950M, 2048MiB)

Traceback (most recent call last): File "C:/Users/USER/.cache/torch/hub/ultralytics_yolov5_master\hubconf.py", line 46, in _create model = DetectMultiBackend(path, device=device) # download/load FP32 model File "C:/Users/USER/.cache/torch/hub/ultralytics_yolov5_master\models\common.py", line 297, in init pt, jit, onnx, xml, engine, coreml, saved_model, pb, tflite, edgetpu, tfjs = self.model_type(w) # get backend File "C:/Users/USER/.cache/torch/hub/ultralytics_yolov5_master\models\common.py", line 476, in model_type from export import export_formats File "C:/Users/USER/.cache/torch/hub/ultralytics_yolov5_master\export.py", line 64, in ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\ntpath.py", line 703, in relpath raise ValueError("path is on mount %r, start on mount %r" % ( ValueError: path is on mount 'C:', start on mount 'D:'

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "D:\Users\a5201\yolococogpu01\detect01.py", line 5, in model = torch.hub.load("C:/Users/USER/.cache/torch/hub/ultralytics_yolov5_master", "custom", path = "D:/Users/a5201/olococogpu01/yolov5/runs/train/exp34/weights/best.pt", source='local' ) File "D:\Users\a5201\yolococogpu01\venv\lib\site-packages\torch\hub.py", line 339, in load model = _load_local(repo_or_dir, model, *args, *kwargs) File "D:\Users\a5201\yolococogpu01\venv\lib\site-packages\torch\hub.py", line 368, in _load_local model = entry(args, **kwargs) File "C:/Users/USER/.cache/torch/hub/ultralytics_yolov5_master\hubconf.py", line 70, in custom return _create(path, autoshape=autoshape, verbose=verbose, device=device) File "C:/Users/USER/.cache/torch/hub/ultralytics_yolov5_master\hubconf.py", line 65, in _create raise Exception(s) from e Exception: path is on mount 'C:', start on mount 'D:'. Cache may be out of date, try force_reload=True or see https://docs.ultralytics.com/yolov5/tutorials/pytorch_hub_model_loading for help.

Process finished with exit code 1

quangdungluong commented 2 years ago

Lets try clone yolov5 repo and copy path. It works for me

polarbear0827 commented 2 years ago

I clone yolov5 and the problem still occurs

polarbear0827 commented 2 years ago

Move entire file to C folder, It can be solved

wonderfuer commented 2 years ago

In general, allocate a directory on Disk C to be used as the running directory of the API site, and then copy restapi.py to solve the problem.

glenn-jocher commented 2 years ago

@polarbear0827 @quangdungluong @chenzhikang I have a proposed fix PR implemented in #7158. Can you please test the PR with this command? If it works I'll merge into master, if it doesn't work please paste your new error message. Thanks!

import torch

model = torch.hub.load('ultralytics/yolov5:fix/relpath', 'yolov5s', force_reload=True)