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

PermissionError when loading a .slp file pointing to a video in /root #116

Closed
davorvr opened this issue Sep 14, 2024 · 1 comment · Fixed by #119
Closed

PermissionError when loading a .slp file pointing to a video in /root #116

davorvr opened this issue Sep 14, 2024 · 1 comment · Fixed by #119

Comments

@davorvr
Copy link

davorvr commented Sep 14, 2024

Hello, I am submitting an issue first referenced here. When trying to import one of the .slp prediction output files using sio.load_file, I'm getting a "permission denied" error.

I believe this is because the cluster I'm running SLEAP on is using a fakeroot container which mounts my home directory with all the necessary files under a directory within /root, which is inaccessible as a regular user outside of the container (i.e. on my own PC). It errors out here:

if type(filename) == str and Path(filename).is_dir():

with a PermissionError. However, sleap-io should be able to load a labels file without being able to directly access its video or the video's parent directories. Below is the full output, which is lengthy, so I put it in a collapsible block:

Commands
$ ipython
Python 3.12.5 | packaged by conda-forge | (main, Aug  8 2024, 18:36:51) [GCC 12.4.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.27.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import sleap_io as sio

In [2]: sio.load_file("/home/davor/ext/banana/models_configs/objects_F2/predictions/rotated_GX010151_right_top_upd.predictions.slp")
Output (error)
---------------------------------------------------------------------------
PermissionError                           Traceback (most recent call last)
Cell In[2], line 1
----> 1 sio.load_file("/home/davor/ext/banana/models_configs/objects_F2/predictions/rotated_GX010151_right_top_upd.predictions.slp")

File ~/miniforge3/lib/python3.12/site-packages/sleap_io/io/main.py:184, in load_file(filename, format, **kwargs)
    181         raise ValueError(f"Could not infer format from filename: '{filename}'.")
    183 if filename.endswith(".slp"):
--> 184     return load_slp(filename, **kwargs)
    185 elif filename.endswith(".nwb"):
    186     return load_nwb(filename, **kwargs)

File ~/miniforge3/lib/python3.12/site-packages/sleap_io/io/main.py:19, in load_slp(filename)
     10 def load_slp(filename: str) -> Labels:
     11     """Load a SLEAP dataset.
     12 
     13     Args:
   (...)
     17         The dataset as a `Labels` object.
     18     """
---> 19     return slp.read_labels(filename)

File ~/miniforge3/lib/python3.12/site-packages/sleap_io/io/slp.py:1016, in read_labels(labels_path)
   1007 """Read a SLEAP labels file.
   1008 
   1009 Args:
   (...)
   1013     The processed `Labels` object.
   1014 """
   1015 tracks = read_tracks(labels_path)
-> 1016 videos = read_videos(labels_path)
   1017 skeletons = read_skeletons(labels_path)
   1018 points = read_points(labels_path)

File ~/miniforge3/lib/python3.12/site-packages/sleap_io/io/slp.py:134, in read_videos(labels_path)
    130 for video_ind, video_data in enumerate(
    131     read_hdf5_dataset(labels_path, "videos_json")
    132 ):
    133     video_json = json.loads(video_data)
--> 134     video = make_video(labels_path, video_json, video_ind=video_ind)
    135     videos.append(video)
    136 return videos

File ~/miniforge3/lib/python3.12/site-packages/sleap_io/io/slp.py:103, in make_video(labels_path, video_json, video_ind)
    100     video_path = backend_metadata["filenames"]
    102 try:
--> 103     backend = VideoBackend.from_filename(
    104         video_path,
    105         dataset=backend_metadata.get("dataset", None),
    106         grayscale=backend_metadata.get("grayscale", None),
    107         input_format=backend_metadata.get("input_format", None),
    108     )
    109 except ValueError:
    110     backend = None

File ~/miniforge3/lib/python3.12/site-packages/sleap_io/io/video.py:87, in VideoBackend.from_filename(cls, filename, dataset, grayscale, keep_open, **kwargs)
     84 if isinstance(filename, Path):
     85     filename = filename.as_posix()
---> 87 if type(filename) == str and Path(filename).is_dir():
     88     filename = ImageVideo.find_images(filename)
     90 if type(filename) == list:

File ~/miniforge3/lib/python3.12/pathlib.py:875, in Path.is_dir(self)
    871 """
    872 Whether this path is a directory.
    873 """
    874 try:
--> 875     return S_ISDIR(self.stat().st_mode)
    876 except OSError as e:
    877     if not _ignore_error(e):

File ~/miniforge3/lib/python3.12/pathlib.py:840, in Path.stat(self, follow_symlinks)
    835 def stat(self, *, follow_symlinks=True):
    836     """
    837     Return the result of the stat() system call on this path, like
    838     os.stat() does.
    839     """
--> 840     return os.stat(self, follow_symlinks=follow_symlinks)

PermissionError: [Errno 13] Permission denied: '/root/mnt/banana/2/NOR/Test/rotated_GX010151_right_top_upd.MP4'
@talmo talmo linked a pull request Sep 29, 2024 that will close this issue
@talmo talmo reopened this Sep 29, 2024
@talmo
Copy link
Contributor

talmo commented Sep 29, 2024

Thanks for cross posting this @davorvr! This should now be fixed in v0.1.9. I tried my best to simulate the conditions indicated by your error, but let me know if you're still not getting it to work on your end.

By default, sleap-io will still try to load the files, but it now should gracefully fail on PermissionErrors and other ways that videos might not be accessible.

If that still doesn't work in your case, you can also now explicitly control this by doing something like:

import sleap_io as sio
slp_path = "/home/davor/ext/banana/models_configs/objects_F2/predictions/rotated_GX010151_right_top_upd.predictions.slp"
labels = sio.load_file(slp_path, open_videos=False)

Let us know if you run into any issues!

Cheers,

Talmo

@talmo talmo closed this as completed Sep 29, 2024
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

Successfully merging a pull request may close this issue.

2 participants