espnet / espnet_model_zoo

ESPnet Model Zoo
Apache License 2.0
243 stars 41 forks source link

Request for a default data folder for fallback #33

Closed lumaku closed 3 years ago

lumaku commented 3 years ago

Downloaded models are stored per default in the package folder. However, when espnet_model_zoo is imported as a system library from a distribution package, its path is read-only.

Proposed solution: Check for output folder access using os.access(modelcache, os.W_OK). If not writeable, default to a different directory, for example $XDG_CACHE_HOME.

Steps to reproduce the issue:

  1. Install espnet_model_zoo as system package.
  2. Use ESPnet as regular user, not as root.
  3. Then download a model file:
    from espnet_model_zoo.downloader import ModelDownloader
    d = ModelDownloader()
    wsjmodel = d.download_and_unpack("kamo-naoyuki/wsj")

    With this, the following exception is thrown:

    
    https://zenodo.org/record/4003381/files/asr_train_asr_transformer_raw_char_valid.acc.ave.zip?download=1: 100%|██████████████████████████████████████████████████████████████████████████████████████████████| 156M/156M [00:09<00:00, 17.0MB/s]
    ---------------------------------------------------------------------------
    PermissionError                           Traceback (most recent call last)
    <ipython-input-3-64ba61e9d85d> in <module>
    ----> 1 wsjmodel = d.download_and_unpack("kamo-naoyuki/wsj")

/usr/lib/python3.9/site-packages/espnet_model_zoo/downloader.py in download_and_unpack(self, name, version, quiet, **kwargs) 288 289 # Download the file to an unique path --> 290 filename = self.download(url, quiet=quiet) 291 292 # Extract files from archived file

/usr/lib/python3.9/site-packages/espnet_model_zoo/downloader.py in download(self, name, version, quiet, **kwargs) 243 # Download the model file if not existing 244 if not (outdir / filename).exists(): --> 245 download(url, outdir / filename, quiet=quiet) 246 247 # Write the url for debugging

/usr/lib/python3.9/site-packages/espnet_model_zoo/downloader.py in download(url, output_path, retry, chunk_size, quiet) 82 pbar.update(len(chunk)) 83 ---> 84 Path(output_path).parent.mkdir(parents=True, exist_ok=True) 85 shutil.move(Path(d) / "tmp", output_path) 86

/usr/lib/python3.9/pathlib.py in mkdir(self, mode, parents, exist_ok) 1310 """ 1311 try: -> 1312 self._accessor.mkdir(self, mode) 1313 except FileNotFoundError: 1314 if not parents or self.parent == self:

PermissionError: [Errno 13] Permission denied: '/usr/lib/python3.9/site-packages/espnet_model_zoo/b2d27107e15dd714684f5767ef10d402'

kamo-naoyuki commented 3 years ago

Sorry, I didn't read this issue. Yeah, fallback is reasonable. I'll implement it.

lumaku commented 3 years ago

Thank you!