talmolab / sleap

A deep learning framework for multi-animal pose tracking.
https://sleap.ai
Other
435 stars 97 forks source link

Trouble loading .analysis.h5 using `sleap.load_file` #1710

Closed Lateef-Saheed closed 7 months ago

Lateef-Saheed commented 8 months ago

Hello! I was attempting to generate a prediction-labeled video using SLEAP v.1.3.3. First I used the information found at "https://sleap.ai/develop/api/sleap.io.dataset.html#sleap.io.dataset.Labels" and found this syntax:

sleap.io.visuals.save_labeled_video(filename: str, labels: sleap.io.dataset.Labels, video: sleap.io.video.Video, frames: List[int], fps: int = 15, scale: float = 1.0, crop_size_xy: Optional[Tuple[int, int]] = None, show_edges: bool = True, edge_is_wedge: bool = False, marker_size: int = 4, color_manager: Optional[sleap.gui.color.ColorManager] = None, palette: str = 'standard', distinctly_color: str = 'instances', gui_progress: bool = False)

Me and the other labmate involved in the project arent that well-versed in python, so we ran into some difficulties. We asked Chat GPT how to call the class sleap.io.dataset.Labels:

import sleap from sleap.io.dataset import Labels dataset_path = "path_to_your_dataset.h5" dataset = sleap.load_file(dataset_path) labels = dataset.labels

After submitting the line: Dataset = sleap.load_file(dataset_path) we received this error message:

dataset = sleap.load_file(dataset_path) /home/ehrlichlab/Documents/Anne/SLEAP_avoidance/Three_Headed_GOAT/SV-Network_12dpf_and_under/VideoDatasetTest/12dpf_under.003_SV5-dpfT6_N22_f2_5dpf-10312022143559-0000.analysis.h5 doesn't match ext for json or json.zip Traceback (most recent call last): File "", line 1, in File "/home/ehrlichlab/mambaforge/envs/sleap/lib/python3.7/site-packages/sleap/io/dataset.py", line 2774, in load_file return Labels.load_file(filename, search_paths, match_to=match_to) File "/home/ehrlichlab/mambaforge/envs/sleap/lib/python3.7/site-packages/sleap/io/dataset.py", line 1969, in load_file filename, for_object="labels", video_search=video_search, *args, *kwargs File "/home/ehrlichlab/mambaforge/envs/sleap/lib/python3.7/site-packages/sleap/io/format/main.py", line 113, in read return disp.read(filename, args, **kwargs) File "/home/ehrlichlab/mambaforge/envs/sleap/lib/python3.7/site-packages/sleap/io/format/dispatch.py", line 59, in read raise TypeError("No file format adaptor could read this file.")

We again asked chat GPT about the issue and it gave us this alternative code:

import sleap dataset_path = "path_to_your_dataset.h5" try: dataset = sleap.load_file(dataset_path) labels = dataset.labels except Exception as e: print("Error loading dataset file:", e)

And again we received an error message in return. Could anyone possibly help us out with the code we used, or suggest a more efficient way of exporting labeled videos? Thanks for the help!

roomrys commented 8 months ago

Hi @Lateef-Saheed,

I am glad you are using GPT. The provided answer is the way you would read in a SLEAP dataset - given it is stored in an .slp file. But, it seems you are trying to read an .analysis.h5 file which is just a normal .h5 file that SLEAP exports all the pose data to after a project is "finished" (after the poses have been estimated using SLEAP).

You can use many different programs to read in an .h5 file, but we have an example notebook written in python to help get you acquainted.

Thanks, LIezl