Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot run model with URL as argument #2246

Closed
ju-w opened this issue Feb 19, 2021 · 6 comments · Fixed by #2250
Closed

Cannot run model with URL as argument #2246

ju-w opened this issue Feb 19, 2021 · 6 comments · Fixed by #2250
Labels
bug Something isn't working

Comments

@ju-w
Copy link

ju-w commented Feb 19, 2021

Hello,

Bug

#2194 broke model.forward() with URLs as argument and subsequently the Colab example https://colab.research.google.com/github/pytorch/pytorch.github.io/blob/master/assets/hub/ultralytics_yolov5.ipynb

Reproduce

e.g. run Colab example.

Trace

ValueError                                Traceback (most recent call last)
<ipython-input-1-86a3d667ec69> in <module>()
      9 
     10 # Inference
---> 11 results = model(imgs)
     12 
     13 # Results

2 frames
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
    725             result = self._slow_forward(*input, **kwargs)
    726         else:
--> 727             result = self.forward(*input, **kwargs)
    728         for hook in itertools.chain(
    729                 _global_forward_hooks.values(),

/root/.cache/torch/hub/ultralytics_yolov5_master/models/common.py in forward(self, imgs, size, augment, profile)
    201             if isinstance(im, str):  # filename or uri
    202                 im = Image.open(requests.get(im, stream=True).raw if im.startswith('http') else im)  # open
--> 203             files.append(Path(im.filename).with_suffix('.jpg').name if isinstance(im, Image.Image) else f'image{i}.jpg')
    204             im = np.array(im)  # to numpy
    205             if im.shape[0] < 5:  # image in CHW

/usr/lib/python3.6/pathlib.py in with_suffix(self, suffix)
    835         name = self.name
    836         if not name:
--> 837             raise ValueError("%r has an empty name" % (self,))
    838         old_suffix = self.suffix
    839         if not old_suffix:

ValueError: PosixPath('.') has an empty name

Reason

yolov5/models/common.py

Lines 201 to 203 in d2e754b

if isinstance(im, str): # filename or uri
im = Image.open(requests.get(im, stream=True).raw if im.startswith('http') else im) # open
files.append(Path(im.filename).with_suffix('.jpg').name if isinstance(im, Image.Image) else f'image{i}.jpg')

An Image created from requests.get download will not have im.filename property set, thus Path(im.filename) will fail.

@ju-w ju-w added the bug Something isn't working label Feb 19, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Feb 19, 2021

👋 Hello @ju-w, 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://www.ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

Python 3.8 or later with all requirements.txt dependencies installed, including torch>=1.7. To install run:

$ pip install -r requirements.txt

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), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

@smartinellimarco
Copy link

I faced the same issue just now. Just wrote a dummy filename into the image's property.
Thanks for sharing!

@glenn-jocher
Copy link
Member

glenn-jocher commented Feb 19, 2021

@ju-w @MarcoCBA thanks for the bug report! Can you provide a minimum reproducible example please?
https://docs.ultralytics.com/help/minimum_reproducible_example/

@glenn-jocher
Copy link
Member

Update, I can reproduce using the default Hub example at https://pytorch.org/hub/ultralytics_yolov5/

Will investigate, this should be working correctly but is not.

@glenn-jocher
Copy link
Member

@ju-w @MarcoCBA this issue is fixed now in #2250. Please retry using the force_reload=True option when loading a new PyTorch Hub model.

Fix verified in Colab.

Screen Shot 2021-02-19 at 11 23 59 AM

@glenn-jocher glenn-jocher removed the TODO label Mar 9, 2021
@glenn-jocher
Copy link
Member

Removed TODO as original issue is resolved in #2250.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants