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

add implementation for label-studio annotations and DeepLabCut #20

Closed
wants to merge 18 commits into from

Conversation

quantumdot
Copy link
Contributor

@quantumdot quantumdot commented Sep 20, 2022

Description

Add support for label-studio and DeepLabCut

Data Model Changes

  • Fix equality of Points. X and Y coordinates were previously compared using normal float equality semantics. Here we change to utilize the numpy.isclose() method for comparison, where two floats are compared for equality within some tolerance (we use just the default tolerances). Additionally, we will consider that two NaN values are equal, which is normally not true.
  • Allow Instance objects to be compared for equality. The points collection within an instance are compared with the rule that both collections of points must contain the same set of nodes, and for each node the point must be equal according to the semantics described above.

Label Studio Support

  • support for reading label-studio annotations from a file or list[dict] and conversion to Labels instance via sleap_io.io.labelstudio.read_labels() and sleap_io.io.labelstudio.parse_tasks()
  • support conversion of Labels to list[dict] via sleap_io.io.labelstudio.write_labels()
  • known issues:
    • label-studio uses relative coordinates (in the range 0-1), so writing label-studio tasks from a labels instance requires that the Video associated with a LabeledFrame properly implement the Video.shape property. If shape is not properly implemented, the label-studio tasks may not function properly.

DeepLabCut Support (single- and multi-animal projects)

  • support for reading DLC annotations and conversion to Labels instance via sleap_io.io.dlc.load_dlc() and sleap_io.io.dlc.dlc_to_labels().
  • support conversion of Labels to DLC annotations via sleap_io.io.dlc.write_dlc() and sleap_io.io.dlc.labels_to_dlc()
  • support determining if the DLC project is a single-animal or a multi-animal style project via sleap_io.io.dlc.is_multianimal()
  • support loading Skeleton data from a DLC project via sleap_io.io.dlc.load_skeletons()
  • known issues:
    • DLC does not include edges in their skeleton definitions, so a skeleton with only nodes and no edges is constructed.
    • Video data may not be properly implemented.
      • I think there is no way for us to know a video or image shape without us first loading it.
      • We currently only set the frame index for an annotation to zero. probably we can parse it from the filename?

Types of changes

  • Bugfix
  • New feature
  • Refactor / Code style update (no logical changes)
  • Build / CI changes
  • Documentation Update
  • Other (explain)

Does this address any currently open issues?

[list open issues here]

Outside contributors checklist

  • Review the guidelines for contributing to this repository
  • Add tests that prove your fix is effective or that your feature works
  • Add necessary documentation (if appropriate)

Thank you for contributing to SLEAP-IO!

❤️

@codecov
Copy link

codecov bot commented Sep 20, 2022

Codecov Report

Merging #20 (5bd7e4f) into main (d8b7b74) will decrease coverage by 6.78%.
The diff coverage is 78.57%.

@@             Coverage Diff             @@
##              main      #20      +/-   ##
===========================================
- Coverage   100.00%   93.21%   -6.79%     
===========================================
  Files           10       11       +1     
  Lines          526      752     +226     
===========================================
+ Hits           526      701     +175     
- Misses           0       51      +51     
Impacted Files Coverage Δ
sleap_io/io/dlc.py 69.92% <69.92%> (ø)
sleap_io/model/instance.py 96.90% <78.57%> (-3.10%) ⬇️
sleap_io/io/labelstudio.py 91.20% <91.20%> (ø)
sleap_io/__init__.py

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@talmo talmo requested a review from roomrys September 22, 2022 21:38
@talmo
Copy link
Contributor

talmo commented Sep 22, 2022

Looking great @quantumdot! Feel free to mark this ready for review for @roomrys whenever you're done.

Tests failing though on equality comparison.
- For points, each attribute of the point is compared, if they all match, the two points are considered equal. For the X and Y attributes, np.isclose() is utilized so that extremely close points are considered equal. Also, NAN are considered equal.
- for instances, we check points by ensuring both instances points contain the same set of nodes, otherwise return false. If they have the same set of nodes, then each node's points between the two instances are compared. If any of these points differ on a node-node basis, the instances are not equal
- compare point coords using np.isclose, to avoid false neg with float stability
- make instances implement __eq__, and compare points using above mentioned semantics
- add test for close points
needed for DLC data, required by pandas
add a test DLC project for testing data
add tests for DLC
@quantumdot quantumdot changed the title add basic implementation for label-studio annotations add implementation for label-studio annotations and DeepLabCut Sep 27, 2022
@quantumdot
Copy link
Contributor Author

@talmo @roomrys I believe I have the bulk of functionality implemented for DLC and label-studio. Perhaps it is a good time to review changes?

We should also discuss Video instances, as some outstanding issues depend on the implementation details there.

@talmo talmo marked this pull request as ready for review September 27, 2022 22:40
@talmo
Copy link
Contributor

talmo commented Sep 27, 2022

@talmo @roomrys I believe I have the bulk of functionality implemented for DLC and label-studio. Perhaps it is a good time to review changes?

We should also discuss Video instances, as some outstanding issues depend on the implementation details there.

Thanks! @roomrys can do the first review. Let's work around the Video stuff for now since that depends on the very unfinished branch at https://github.com/talmolab/sleap-io/tree/talmo/pims-video-backend.

@quantumdot
Copy link
Contributor Author

CI / Tests are failing on python==3.7 it seems due to pickle protocol version mismatch. See related: DeepLabCut/DLCutils#19. Do you have a DLC dataset which works across the python version 3.8 boundary, where pickle version changed from 4 -> 5?

CI / Tests fail on windows python==3.9 due to an import error for pytables. I don't understand why.

@talmo
Copy link
Contributor

talmo commented Sep 28, 2022

Hi @quantumdot,

Ok, maybe let's split this up into two PRs? You can copy over dlc.py and the test data into a new branch where we can start to work around some of these version issues.

Talmo

@quantumdot
Copy link
Contributor Author

Closing this PR as it is superseded by the following (these changes split into three separate PRs based on separation of concerns)

@quantumdot quantumdot closed this Oct 26, 2022
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 this pull request may close these issues.

2 participants