LorenFrankLab / spyglass

Neuroscience data analysis framework for reproducible research built by Loren Frank Lab at UCSF
https://lorenfranklab.github.io/spyglass/
MIT License
94 stars 43 forks source link

`make_video` fails with opencv #1156

Closed emreybroyles closed 2 weeks ago

emreybroyles commented 1 month ago

Describe the bug Some of the populate calls in the DLC pipeline aren't working and output {'success_count': 0, 'error_list': []} after updating spyglass and the spyglass-dlc environment, in attempts to fix the bug in #1146

To Reproduce Steps to reproduce the behavior:

dlc_key = {'nwb_file_name': 'SC100220231007_.nwb', 'epoch': 11, 'video_file_num': 16, 'project_name': 'sideSleep_LED', 'dlc_model_name': 'sideSleep_LED_tutorial_00', 'dlc_model_params_name': 'default', 'dlc_centroid_params_name': 'default', 'dlc_si_cohort_centroid': 'green_red_led', 'dlc_si_cohort_orientation': 'green_red_led', 'dlc_orientation_params_name': 'default'}

sgp.DLCPosV1().populate(dlc_key) sgp.DLCPosVideo().populate(dlc_key)

  1. This error is on file eb_notebooks/DLCNotebooks/21_DLC_sideSleep_LED.ipynb
  2. see the cells with the populate calls listed above

Expected behavior The populate calls will work

Screenshots image

CBroz1 commented 1 month ago

Please post bugs with a snippet that can be run directly, without referring to outside material

This is the expected outcome for populating a key that has already been run. Please check that your keys are present in the list of unprocessed keys, Table.key_source

emreybroyles commented 1 month ago

Oh okay I see. So in the case of the video population in particular sgp.DLCPosVideo().populate(dlc_key) that I use to create a video with centroid and orientation overlaid to ensure my model is accurately labeling specific body parts, it looks like I already ran it before (but something wasn't working properly the first time). I wanted to run it again to actually be able to look at the video it created. From the source code it seems like this video isn't actually saved anywhere/I can't find the directory; it usually just outputs the video in the notebook itself after the cell runs. @CBroz1 Do you know how I can view this video then?

CBroz1 commented 1 month ago

This is what determines where your video is saved: https://github.com/LorenFrankLab/spyglass/blob/03e39960e31bb358ba3f112220a5fdbb2e6acc76/src/spyglass/position/v1/position_dlc_selection.py#L399-L407

With the output dir stored in DLCPoseEstimationSelection https://github.com/LorenFrankLab/spyglass/blob/master/src/spyglass/position/v1/position_dlc_selection.py#L364-L371

If it did not display the video as normal, I'd recommend reverting to version 0.5.1 and rerunning. If that fixes the issue, then this is a bug introduced in #870

emreybroyles commented 1 month ago

Thank you for pointing that code out to me! So I did find thatsgp.DLCPoseEstimationSelection() & dlc_key gives pose_estimation_output_dir = /nimbus/deeplabcut/output/SC100220231007/SC100220231007_11_model_sideSleep_LED_tutorial_00 and there is no mp4 file in that directory. Next I will revert spyglass to 0.5.1 to see if the video is created.

emreybroyles commented 1 month ago

Reverted to 0.5.1 and am still getting the same outputs with no video created

CBroz1 commented 1 month ago

It appears that there's an upper limit on the number of digits that the video file name can contain, relevant post. I found this by googling the error I saw in the output: (-215:Assertion failed) number < max_number in function 'cv::icvExtractPattern'

I generated the video with a different name. Please check the folder you mentioned above for TEST_VIDEO.mp4 and let me know if that looks right. If so, I can make some edits to have the video maker save to a temporary directory, and then copy it to the right location afterward

emreybroyles commented 1 month ago

Thanks Chris. TEST_VIDEO.mp4 does not look correct- it doesn't have the centroid or orientation overlaid; it just looks like the video colors were changed- almost inverted

CBroz1 commented 1 month ago

It looks like the correct video can be generated with 0.5.1 and using the matplotlib processor

CBroz1 commented 1 month ago

Future work will ...

CBroz1 commented 2 weeks ago

Closed with #1174, #1168