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

Error fetching images will fail the infer method #21

Open
eitantorf opened this issue May 30, 2021 · 5 comments
Open

Error fetching images will fail the infer method #21

eitantorf opened this issue May 30, 2021 · 5 comments
Assignees

Comments

@eitantorf
Copy link

I am trying to run transform_jsonl (to download images and prepare m3 json file) and right after running the infer method - the issue occurs when transform_jsonl does not find some images but still writes the path to the m3 json file, causing the infer to fail over:
FileNotFoundError: [Errno 2] No such file or directory

@computermacgyver
Copy link
Member

computermacgyver commented May 30, 2021

Thank you @eitantorf for letting us know.

We're supposed to catch this and replace with the "default image" if the image is unavailable:

if not os.path.exists(img_file_resize):
img_file_resize = TW_DEFAULT_PROFILE_IMG

I'll have to look into it further. Would you be able to share an example of input and errant output? I'm curious if it is supposed to be a path to the default image but that the default image is unavailable or something else.

@computermacgyver computermacgyver self-assigned this May 30, 2021
@eitantorf
Copy link
Author

Ah I see you fixed it, great.
My code is the previous one I now see, maybe the pip install version does not include this fix?

@computermacgyver
Copy link
Member

I'll check what on pip. Thanks, @eitantorf

@zijwang
Copy link
Member

zijwang commented Jun 2, 2021

Thanks, @eitantorf and @computermacgyver! I have pushed the latest version to pypi. @eitantorf , could you try updating the package and see whether the issue persists?

@davidjurgens
Copy link
Member

It might be worth extending this behavior to all image-related errors during inference. Here's one I just ran into where the file type can't be inferred, which causes the whole infer call to error out:

UnidentifiedImageError: Caught UnidentifiedImageError in DataLoader worker process 3.
Original Traceback (most recent call last):
  File "/opt/anaconda/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 202, in _worker_loop
    data = fetcher.fetch(index)
  File "/opt/anaconda/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/opt/anaconda/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/opt/anaconda/lib/python3.8/site-packages/m3inference/dataset.py", line 37, in __getitem__
    return self._preprocess_data(data)
  File "/opt/anaconda/lib/python3.8/site-packages/m3inference/dataset.py", line 43, in _preprocess_data
    fig = self._image_loader(img_path)
  File "/opt/anaconda/lib/python3.8/site-packages/m3inference/dataset.py", line 91, in _image_loader
    image = Image.open(image_name)
  File "/opt/anaconda/lib/python3.8/site-packages/PIL/Image.py", line 2958, in open
    raise UnidentifiedImageError(
PIL.UnidentifiedImageError: cannot identify image file 'someimage.jpg'

It's probably worth not failing in those cases and just printing a warning. That, or adding some kind of pandas-like flag errors='ignore' as the default and let the users decide if the infer should stop on error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants