facebookresearch / WSL-Images

Weakly Supervised Learning On Images
Other
599 stars 63 forks source link

OSError: [Errno 22] Invalid argument #7

Open rafis opened 5 years ago

rafis commented 5 years ago

OS: Windows 7 Python: v3.7.4 PyTorch: v1.2.0 Model: resnext101_32x48d_wsl

      1 import torch
----> 2 model = torch.hub.load('facebookresearch/WSL-Images', 'resnext101_32x48d_wsl')
      3 model.eval()

c:\dev\python37\lib\site-packages\torch\hub.py in load(github, model, *args, **kwargs)
    361     entry = _load_entry_from_hubconf(hub_module, model)
    362 
--> 363     model = entry(*args, **kwargs)
    364 
    365     sys.path.remove(repo_dir)

~/.cache\torch\hub\facebookresearch_WSL-Images_master/hubconf.py in resnext101_32x48d_wsl(progress, **kwargs)
     76     kwargs['groups'] = 32
     77     kwargs['width_per_group'] = 48
---> 78     return _resnext('resnext101_32x48d', Bottleneck, [3, 4, 23, 3], True, progress, **kwargs)

~/.cache\torch\hub\facebookresearch_WSL-Images_master/hubconf.py in _resnext(arch, block, layers, pretrained, progress, **kwargs)
     22 def _resnext(arch, block, layers, pretrained, progress, **kwargs):
     23     model = ResNet(block, layers, **kwargs)
---> 24     state_dict = load_state_dict_from_url(model_urls[arch], progress=progress)
     25     model.load_state_dict(state_dict)
     26     return model

c:\dev\python37\lib\site-packages\torch\hub.py in load_state_dict_from_url(url, model_dir, map_location, progress)
    461         hash_prefix = HASH_REGEX.search(filename).group(1)
    462         _download_url_to_file(url, cached_file, hash_prefix, progress=progress)
--> 463     return torch.load(cached_file, map_location=map_location)

c:\dev\python37\lib\site-packages\torch\serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
    384         f = f.open('rb')
    385     try:
--> 386         return _load(f, map_location, pickle_module, **pickle_load_args)
    387     finally:
    388         if new_fd:

c:\dev\python37\lib\site-packages\torch\serialization.py in _load(f, map_location, pickle_module, **pickle_load_args)
    578     for key in deserialized_storage_keys:
    579         assert key in deserialized_objects
--> 580         deserialized_objects[key]._set_from_file(f, offset, f_should_read_directly)
    581         if offset is not None:
    582             offset = f.tell()

OSError: [Errno 22] Invalid argument

maybe because it is biggest pre-trained model (more than 2GB) and maybe because Python has bugs in pickle on Windows?

MELGABSI commented 5 years ago

Having the exact same problem (only difference is that i'm on windows 10)...

dkm2110 commented 5 years ago

Hey Apologies for not responding earlier. Let me repro it and get back. Meanwhile did you try other models and do they work?

MELGABSI commented 5 years ago

Thank you for your response. In my end, i'm not facing any issues with the models i've tested (i'm in the middle of testing them all and i'll give a final full report of all the models i face issues with if any...). but if it could help you, i loaded a simple resnet using another method just for testing and i faced the exact same error while loading the FixResNeXt-101 32x48d V2 weights using this ligne of code pretrained_dict=torch.load('ResNeXt101_32x48d.pth',map_location='cpu')['model'] i'm not reporting the issue here because it's not the repository for but the intersting point is that the same file (torch\serialization.py) and the same lignes are causing this problem (i can post the error msg if you need to). and i solved it using the buffer loading method. with open('FixResNeXt101_32x48d_v2.pth', 'rb') as f: ---buffer = io.BytesIO(f.read()) pretrained_dict=torch.load(buffer) just putting this here not sure if it'll help you resolving the issue... it's worth noting that the resnext101_32x48d_wsl works perfectly on ubuntu (just tested it using VM VirtualBox).

ssbarnea commented 2 years ago

Considering that I randomly see our wsl1 (GHA) pipeline fail, with OSError 22, I assume that this is till broken in 2022

  File "/mnt/d/a/ansible-lint/ansible-lint/src/ansiblelint/file_utils.py", line 418, in check_suite_focus=true#step:10:114)
    if item.path.is_dir():
  File "/usr/lib/python3.9/pathlib.py", line 1422, in is_dir
    return S_ISDIR(self.stat().st_mode)
  File "/usr/lib/python3.9/pathlib.py", line 1221, in stat
    return self._accessor.stat(self)
OSError: [Errno 22] Invalid argument: 'examples/roles/template_lookup/files/a_file'

As you can see the exception comes from python and on a file that is perfectly fine, job runs task under WSL, not windows. It is relatively rare but still occurs.