Skip to content

Conversation

@rahulporuri
Copy link
Contributor

@rahulporuri rahulporuri commented Jul 16, 2022

deeplabcut.filterpredictions at the moment returns None. Internally, there are two try/except blocks. The first try/except block looks for existing filtered data. The second try/except block looks for analyzed data to filter.

This PR does the following -

  • In the first commit, the second/inner try/except block is pulled out of the first try/except block. The first try/except block continues to the next video in the for loop if filtered data is found.
  • In the second commit, the scope of the second try/except block is narrowed. Instead of finding and filtering the analyzed data in the try block, the try block only looks for the analyzed data now and the filtering happens outside.
  • In the third and final commit, the PR stores the mapping between video filename and the corresponding filtered data. If no videos are found, an empty dictionary is returned and if analyzed data isnt found, None is returned for the corresponding video filename.

Similarly, deeplabcut.analyze_skeleton at the moment returns None.

Similar to change in deeplabcut.filterpredictions earlier, the scope of the try/except is also reduced - now the skeleton calculations are performed outside the try/except block. And deeplabcut.analyze_skeleton returns a mapping from the video filename to the corresponding skeleton data. If analyzed data isn't found for a given video filename, None will be used and if a pre-existing skeleton data file is found, a dataframe will be loaded from the file.

This addresses one of the points mentioned in #1895 - deeplabcut functions returning information instead of returning None.

Note to reviewer : It might be easier to review this PR one-commit-at-a-time.

Poruri Sai Rahul added 3 commits July 16, 2022 10:04
there were two try/excepts, one within the other.
this commit simplifies the code by pulling the inner try/except out.

the code now tries to look for filtered data. if filtered data is found
for the video, we continue to the next item in the loop.

if not found, we catch and ignore the error. we then try to load the
data and filter it

	modified:   deeplabcut/post_processing/filtering.py
the second try block in filterpredictions looked for the analyzed file
and performed operations to filter it - and if the file is not found,
continue to the next item in the for loop.

this commit reduces the try block to only load the analyzed file and
immediately catch the error and continue if the file doesnt exist.

the rest of the filtering on the analyzed data is performed outside the
try/except block.

	modified:   deeplabcut/post_processing/filtering.py
the filterpredictions now returns a mapping instead of returning None.

	modified:   deeplabcut/post_processing/filtering.py
@rahulporuri rahulporuri changed the title "deeplabcut.filterpredictions" returns a mapping from video to filtered dataframe "deeplabcut.filterpredictions" and "deeplabcut.analyze_skeleton" return mappings Jul 16, 2022
Poruri Sai Rahul added 3 commits July 16, 2022 10:27
instead of finding and analyzing the skeleton in the try block, this
commit reduces the scope of the try block to only finding the file and
moves the skeleton calculations to outside the try/except.

	modified:   deeplabcut/post_processing/analyze_skeleton.py
	modified:   deeplabcut/post_processing/filtering.py
the analyze_skeleton function now returns a mapping instead of None

	modified:   deeplabcut/post_processing/analyze_skeleton.py
@MMathisLab MMathisLab requested a review from jeylau July 17, 2022 00:17
@jeylau
Copy link
Contributor

jeylau commented Jul 19, 2022

Thanks @rahulporuri! Looks great to me!
Just curious, how is that dict output being used on your side afterwards? ☺️

@rahulporuri
Copy link
Contributor Author

Thanks for the quick review @jeylau .

Just curious, how is that dict output being used on your side afterwards?

I can't go into the full details but like I mentioned in #1895 , we're using DeepLabCut within a larger application. This specific PR allows us to directly get data back from the API instead of reading it back from files.

I wanted to go further and add additional API kwargs to prevent the files from being saved but I didn't want to propose more changes than were necessary.

@rahulporuri
Copy link
Contributor Author

@jeylau do you know if there's any plan to normalize naming in the codebase e.g. renaming functions to use underscores instead of CamelCase naming convention in auxfun_models and auxiliaryfunctions. If yall are open to the changes, I can open PRs. The differences in convention are slowly getting on my nerves now 😅

@jeylau
Copy link
Contributor

jeylau commented Jul 20, 2022

Renaming functions to snake case is something we gradually do when refactoring/cleaning code. We're definitely more than happy to get a bit of help here too! 😄

@AlexEMG
Copy link
Member

AlexEMG commented Jul 20, 2022

Good addition, but I think we should make flag: returndata=True or so, so that one has control.

@rahulporuri
Copy link
Contributor Author

Good addition, but I think we should make flag: returndata=True or so, so that one has control.

I'd actually flip it the other way around - add a save=True flag which the caller can set to False if necessary. But like I mentioned earlier, the APIs already has a lot of arguments so I thought i'll leave this change for a later PR.

@MMathisLab MMathisLab requested a review from AlexEMG August 8, 2022 12:27
@AlexEMG
Copy link
Member

AlexEMG commented Aug 31, 2022

I think it's best to set the flags so that the functionality is stable with respect to prior versions.

@MMathisLab
Copy link
Member

hi all, what's the decision on this PR?

@MMathisLab
Copy link
Member

shall we add the flags cc @AlexEMG @rahulporuri @n-poulsen ? or close?

@MMathisLab MMathisLab added the enhancement New feature or request label May 25, 2023
@MMathisLab
Copy link
Member

Bump to dev team! ^

@n-poulsen
Copy link
Contributor

I think adding the flags is a great idea

@MMathisLab
Copy link
Member

@n-poulsen can you add the flag so we can merge/close this PR?

@jeylau
Copy link
Contributor

jeylau commented Oct 3, 2023

@AlexEMG @MMathisLab flag added, good to merge now! Thanks @rahulporuri, sorry for getting back to your PR only now!

@rahulporuri
Copy link
Contributor Author

@AlexEMG @MMathisLab flag added, good to merge now! Thanks @rahulporuri, sorry for getting back to your PR only now!

I apologize for not making the time to come back to my PR. Thank you very much for continuing to work on it!

@jeylau jeylau merged commit 9ea18e3 into DeepLabCut:main Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants