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

Backward compatible (1.3.0a0 > 1.2.2 to 1.2.6) #1217

Closed
aereimer opened this issue Mar 11, 2023 · 13 comments
Closed

Backward compatible (1.3.0a0 > 1.2.2 to 1.2.6) #1217

aereimer opened this issue Mar 11, 2023 · 13 comments
Labels
bug Something isn't working

Comments

@aereimer
Copy link

"Greetings! I recently experimented with the alpha version 1.3.0a0 of and tested it by opening a project that I initiated in previous versions (1.2.2 to 1.2.6). I added some additional labeled frames, trained the model, and performed successful inferences. However, I encountered issues when attempting to convert the h5 output to slp and then the slp file to csv using a script by @Toshea111 (#1089 (comment)). I suspect that the incompatibility problem might be related to changes in the file structure of the new version's output. Could you confirm if this issue is due to a bug in the newest version or if the file structure of the new version has indeed changed?"

@talmo
Copy link
Collaborator

talmo commented Mar 11, 2023

Hi @aereimer,

Do you mind sharing the specific error you're getting now? That'll help narrow down the cause.

Cheers,

Talmo

@aereimer
Copy link
Author

aereimer commented Mar 11, 2023

Hi @talmo, sorry for not pasting the log here before. So, here I tried to open the slp project (created initially in 1.2.2, modified in 1.2.6, and finally modified and saved using 1.3.0a0) using versions < 1.3.0a0 versions. The error below appears specifically when I tried to open the project using version 1.2.6 ( the same thing happened with other versions, such as 1.2.9). Just one thing, I did not modified the skeleton or added more bodyparts while using the 1.3.0a0 . Thanks for checking this! Parabéns pelo excelente trabalho!

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\envs\sleap_develop\lib\site-packages\sleap\gui\commands.py", line 262, in openProject
    self.execute(OpenProject, filename=filename, first_open=first_open)
  File "C:\ProgramData\Anaconda3\envs\sleap_develop\lib\site-packages\sleap\gui\commands.py", line 240, in execute
    command().execute(context=self, params=kwargs)
  File "C:\ProgramData\Anaconda3\envs\sleap_develop\lib\site-packages\sleap\gui\commands.py", line 137, in execute
    self.do_with_signal(context, params)
  File "C:\ProgramData\Anaconda3\envs\sleap_develop\lib\site-packages\sleap\gui\commands.py", line 161, in do_with_signal
    cls.do_action(context, params)
  File "C:\ProgramData\Anaconda3\envs\sleap_develop\lib\site-packages\sleap\gui\commands.py", line 606, in do_action
    context.app.loadProjectFile(filename)
  File "C:\ProgramData\Anaconda3\envs\sleap_develop\lib\site-packages\sleap\gui\app.py", line 1451, in loadProjectFile
    labels = Labels.load_file(filename, video_search=gui_video_callback)
  File "C:\ProgramData\Anaconda3\envs\sleap_develop\lib\site-packages\sleap\io\dataset.py", line 1943, in load_file
    filename, for_object="labels", video_search=video_search, *args, **kwargs
  File "C:\ProgramData\Anaconda3\envs\sleap_develop\lib\site-packages\sleap\io\format\main.py", line 113, in read
    return disp.read(filename, *args, **kwargs)
  File "C:\ProgramData\Anaconda3\envs\sleap_develop\lib\site-packages\sleap\io\format\dispatch.py", line 56, in read
    return adaptor.read(file, *args, **kwargs)
  File "C:\ProgramData\Anaconda3\envs\sleap_develop\lib\site-packages\sleap\io\format\hdf5.py", line 139, in read
    labels = cls.read_headers(file, video_search, match_to)
  File "C:\ProgramData\Anaconda3\envs\sleap_develop\lib\site-packages\sleap\io\format\hdf5.py", line 124, in read_headers
    labels = labels_json.LabelsJsonAdaptor.from_json_data(dicts, match_to=match_to)
  File "C:\ProgramData\Anaconda3\envs\sleap_develop\lib\site-packages\sleap\io\format\labels_json.py", line 384, in from_json_data
    dicts["skeletons"], List[Skeleton]
  File "C:\ProgramData\Anaconda3\envs\sleap_develop\lib\site-packages\cattr\converters.py", line 201, in structure
    return self._structure_func.dispatch(cl)(obj, cl)
  File "C:\ProgramData\Anaconda3\envs\sleap_develop\lib\site-packages\cattr\converters.py", line 336, in _structure_list
    for e in obj
  File "C:\ProgramData\Anaconda3\envs\sleap_develop\lib\site-packages\cattr\converters.py", line 336, in <listcomp>
    for e in obj
  File "C:\ProgramData\Anaconda3\envs\sleap_develop\lib\site-packages\sleap\skeleton.py", line 248, in <lambda>
    Skeleton, lambda x, cls: Skeleton.from_dict(x, idx_to_node)
  File "C:\ProgramData\Anaconda3\envs\sleap_develop\lib\site-packages\sleap\skeleton.py", line 931, in from_dict
    return Skeleton.from_json(json.dumps(d), node_to_idx)
  File "C:\ProgramData\Anaconda3\envs\sleap_develop\lib\site-packages\sleap\skeleton.py", line 1030, in from_json
    graph = json_graph.node_link_graph(jsonpickle.decode(json_str))
  File "C:\ProgramData\Anaconda3\envs\sleap_develop\lib\site-packages\networkx\readwrite\json_graph\node_link.py", line 166, in node_link_graph
    for d in data["nodes"]:
KeyError: 'nodes'

@Toshea111
Copy link

Dear aereimer,

The issue might be that you are trying to convert '.slp' files, when the notebook is designed for converting '.h5' files to '.csv'.

Try directly inputting the '.h5' output, rather than converting it into '.slp' format first.

Best wishes,

Thomas

@aereimer
Copy link
Author

aereimer commented Mar 13, 2023

Dear @Toshea111,

Thanks for pointing this out. I believe I’ve tried first the slp file because the colab file originally was pointing to a slp file ( [email protected] ). But I also tried the h5 file (exported from SLEAP v1.3.0a0 ) and it did not work, the error message is below - that's also the reason I've asked about changes in the output file in this newer version.

Thanks once again for you input.
Best,
Adriano

`KeyError Traceback (most recent call last)
in
----> 1 labels = sio.load_slp("labels.v001.014_R23_EPM_session_1_20211206_22_adjusted.analysis.h5")
2 # labels = sleap.load_file("sleap1.3")
3 labels

4 frames
/usr/local/lib/python3.9/dist-packages/sleap_io/io/main.py in load_slp(filename)
17 The dataset as a Labels object.
18 """
---> 19 return slp.read_labels(filename)
20
21

/usr/local/lib/python3.9/dist-packages/sleap_io/io/slp.py in read_labels(labels_path)
239 The processed Labels object.
240 """
--> 241 tracks = read_tracks(labels_path)
242 videos = read_videos(labels_path)
243 skeletons = read_skeletons(labels_path)

/usr/local/lib/python3.9/dist-packages/sleap_io/io/slp.py in read_tracks(labels_path)
57 A list of Track objects.
58 """
---> 59 tracks = [json.loads(x) for x in read_hdf5_dataset(labels_path, "tracks_json")]
60 track_objects = []
61 for track in tracks:

/usr/local/lib/python3.9/dist-packages/sleap_io/io/utils.py in read_hdf5_dataset(filename, dataset)
20 """
21 with h5py.File(filename, "r") as f:
---> 22 data = f[dataset][()]
23 return data
24

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

/usr/local/lib/python3.9/dist-packages/h5py/_hl/group.py in getitem(self, name)
286 raise ValueError("Invalid HDF5 object reference")
287 else:
--> 288 oid = h5o.open(self.id, self._e(name), lapl=self._lapl)
289
290 otype = h5i.get_type(oid)

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/h5o.pyx in h5py.h5o.open()

KeyError: "Unable to open object (object 'tracks_json' doesn't exist)"`

@Toshea111
Copy link

Dear aereimer,

Looking at the link, I think that is an older version of the notebook.

There is an updated version here:

https://github.com/Toshea111/sleap/blob/develop/docs/notebooks/Convert_HDF5_to_CSV_updated.ipynb

Let me know if the issue persists.

Best wishes,

Thomas

@roomrys
Copy link
Collaborator

roomrys commented Mar 14, 2023

Hi @aereimer,

I can sheepishly confirm that the file structure has changed. We added two new attributes in the Skeleton class called description and preview_image. Consequently, while you are able to open older files on v1.3.0a0, files from this version are unable to be opened on previous versions - which is not a problem if working on a single SLEAP version. However, I can see how this could easily become extremely annoying if working on multiple workstations which all have different versions of SLEAP installed.

The field we added is currently not used except for provided template skeletons, so we could selectively write the field depending on whether the skeleton is a template (manually specified via API - only by those looking to add to our collection of template skeletons). I opened PR #1222 to rectify this.

Thanks,
Liezl

@aereimer
Copy link
Author

Dear @Toshea111,

I have tried the new script that you shared, and it works great! It is compatible with all SLEAP versions that I have tested. I made minor changes to the script to suit my project's requirements (as it has a single track; I still wanted to get the score for each body part/frame), but apart from that, it is perfect. Thank you once again for sharing the notebook!

Best,
Adriano

@aereimer
Copy link
Author

Dear @roomrys,

Thanks for getting back to me and for your prompt attention to this matter.

Best,
Adriano

@Toshea111
Copy link

Dear Adriano,

Excellent, and good to hear that it works with the latest version.

@roomrys I am happy to incorporate this into a future analysis notebook, if that would be useful?

Best wishes,

Thomas

@roomrys roomrys added bug Something isn't working open pr A fix has been written, but is still being reviewed. labels Mar 15, 2023
@roomrys
Copy link
Collaborator

roomrys commented Mar 15, 2023

Hi @Toshea111,

Yes! This notebook is gaining a lot of traction. We could even convert your notebook into an adaptor for using in the GUI/API/CLI instead of having it as a separate entity. If you start a PR, we can collaborate (not sure if you would be able work on a talmolab/sleap branch, but I can pop to your fork to get the basic structure set-up). We would need to

  1. Add an adaptor file to the format folder which implements a subclass of the Adaptor class

    @attr.s(auto_attribs=True)
    class Adaptor:
    """
    File format adaptor base class.
    An adaptor handles reading and/or writing a specific file format. To add
    support for a new file format, you'll create a new class which inherits from
    the Adaptor base class and implements the relevant functions.
    """

  2. Connect the adaptor to the GUI (various places)

  3. Connect the adaptor to the sleap-convert command

    sleap/sleap/io/convert.py

    Lines 100 to 105 in 4bd0171

    def main(args: list = None):
    """Entrypoint for `sleap-convert` CLI for converting .slp to different formats.
    Args:
    args: A list of arguments to be passed into sleap-convert.
    """

I think copying some of the notebook code into the different methods in the adaptor would be a great start for integration. Let me know what you think. Totally understand if this is more than what you wanted to bite off, and I can take over whatever you'd rather not tackle at the moment.

Thanks,
Liezl

@roomrys roomrys added fixed in future release Fix or feature is merged into develop and will be available in future release. and removed open pr A fix has been written, but is still being reviewed. labels Mar 16, 2023
@Toshea111
Copy link

Dear Liezl,

I would be happy to collaborate, although I fear that my expertise is limited.

I made the fork 'Toshea111/sleap' a while back, and will invite you as a collaborator.

The notebook is currently located in:

https://github.com/Toshea111/sleap/tree/develop/docs/notebooks

The impetus for the notebook is some downstream software that I am working on, thus further integration would be useful.

Best wishes,

Thomas

@roomrys roomrys closed this as completed Mar 24, 2023
@roomrys
Copy link
Collaborator

roomrys commented Mar 24, 2023

This fix is now available in the latest release v1.3.0. To install:

conda create -y -n sleap -c sleap -c nvidia -c conda-forge sleap=1.3.0

@roomrys roomrys removed the fixed in future release Fix or feature is merged into develop and will be available in future release. label Mar 24, 2023
@Toshea111
Copy link

Dear Liezl,

Much appreciated.

Best wishes,

Thomas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants