dattalab / keypoint-moseq

https://keypoint-moseq.readthedocs.io
Other
68 stars 28 forks source link

"ValueError: cannot reshape array of size 0 into shape (0,newaxis)" when loading data #36

Closed juliagorman closed 1 year ago

juliagorman commented 1 year ago

Moving through the tutorial to load data, I keep getting this error with various h5 files I am trying. In the past I was able to run kp moseq on a data set and then all i did was create more h5 files to test and these new ones I cant get past this line with.

Screenshot 2023-05-04 at 12 03 16 PM
calebweinreb commented 1 year ago

It may be that some of the these files have all NaNs for one of the keypoints. If you send me the file I can try to figure out the issue.

calebweinreb commented 1 year ago

Based on the files you sent, the problem is that "l_finger_4" and "l_finger_5" are NaN in all the frames from "/Users/calebweinreb/Downloads/Buck_20221031_pt1_c3.h5". For now you can solve the error by excluding these bodyparts from the "use_bodyparts" list in the config. Here is a list of other bodyparts with a high number NaNs:

r_eye is NaN in 59.9% of frames from Buck_20221031_pt1_c1 l_eye is NaN in 69.5% of frames from Buck_20221031_pt1_c1 l_eye is NaN in 53.8% of frames from Buck_20221031_pt1_c2 l_finger_2 is NaN in 54.2% of frames from Buck_20221031_pt1_c2 l_finger_4 is NaN in 85.9% of frames from Buck_20221031_pt1_c2 l_finger_5 is NaN in 81.1% of frames from Buck_20221031_pt1_c2 l_toe_3 is NaN in 52.6% of frames from Buck_20221031_pt1_c2 l_eye is NaN in 86.5% of frames from Buck_20221031_pt1_c3 l_finger_1 is NaN in 85.0% of frames from Buck_20221031_pt1_c3 l_finger_2 is NaN in 90.0% of frames from Buck_20221031_pt1_c3 l_finger_4 is NaN in 100.0% of frames from Buck_20221031_pt1_c3 l_finger_5 is NaN in 100.0% of frames from Buck_20221031_pt1_c3 r_foot is NaN in 73.4% of frames from Buck_20221031_pt1_c3

https://github.com/dattalab/keypoint-moseq/commit/21226e5c72132d17e79969fd998c3e014683878c will prevent this error in the future releases.

juliagorman commented 1 year ago

I started with just removing the l_finger_4, and l_finger_5 and was able to run that command, however when generating the scree plot for the PCA I ran into this error. I commented it out just to see if I could keep going and was able to visualize the 10 PCs. However, I then ran into this error when fitting the model. Is this also an issue of not removing enough NaNs? It to me looks like its an issue somehow with the PCA but I am not sure. I also tried multiple files and still ran into this issue.

JC Gorman PhD student | Millerhttps://millerlab.ucsd.edu/ lab Neurosciences Graduate Program | UCSD


From: Caleb Weinreb @.> Sent: Thursday, May 4, 2023 4:13 PM To: dattalab/keypoint-moseq @.> Cc: Julia C Gorman @.>; Author @.> Subject: Re: [dattalab/keypoint-moseq] "ValueError: cannot reshape array of size 0 into shape (0,newaxis)" when loading data (Issue #36)

Based on the files you sent, the problem is that "l_finger_4" and "l_finger_5" are NaN in all the frames from "/Users/calebweinreb/Downloads/Buck_20221031_pt1_c3.h5". For now you can solve the error by excluding these bodyparts from the "use_bodyparts" list in the config. Here is a list of other bodyparts with a high number NaNs:

r_eye is NaN in 59.9% of frames from Buck_20221031_pt1_c1 l_eye is NaN in 69.5% of frames from Buck_20221031_pt1_c1 l_eye is NaN in 53.8% of frames from Buck_20221031_pt1_c2 l_finger_2 is NaN in 54.2% of frames from Buck_20221031_pt1_c2 l_finger_4 is NaN in 85.9% of frames from Buck_20221031_pt1_c2 l_finger_5 is NaN in 81.1% of frames from Buck_20221031_pt1_c2 l_toe_3 is NaN in 52.6% of frames from Buck_20221031_pt1_c2 l_eye is NaN in 86.5% of frames from Buck_20221031_pt1_c3 l_finger_1 is NaN in 85.0% of frames from Buck_20221031_pt1_c3 l_finger_2 is NaN in 90.0% of frames from Buck_20221031_pt1_c3 l_finger_4 is NaN in 100.0% of frames from Buck_20221031_pt1_c3 l_finger_5 is NaN in 100.0% of frames from Buck_20221031_pt1_c3 r_foot is NaN in 73.4% of frames from Buck_20221031_pt1_c3

21226e5https://urldefense.com/v3/__https://github.com/dattalab/keypoint-moseq/commit/21226e5c72132d17e79969fd998c3e014683878c__;!!Mih3wA!GRVyTNurM82DyskcNsNNbYaFBM8GLGzvyGDYat6VMuVHDffqjVLbaVM6lWgl7ZMH5Xh2JRMpEnIaUPtlJJt6cLarig$ will prevent this error in the future releases.

— Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https://github.com/dattalab/keypoint-moseq/issues/36*issuecomment-1535516585__;Iw!!Mih3wA!GRVyTNurM82DyskcNsNNbYaFBM8GLGzvyGDYat6VMuVHDffqjVLbaVM6lWgl7ZMH5Xh2JRMpEnIaUPtlJJuS0wXxDA$, or unsubscribehttps://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AHXPYCOHMXNLB73JO4WFZWLXEQZYHANCNFSM6AAAAAAXWFV4TM__;!!Mih3wA!GRVyTNurM82DyskcNsNNbYaFBM8GLGzvyGDYat6VMuVHDffqjVLbaVM6lWgl7ZMH5Xh2JRMpEnIaUPtlJJtcq22AmA$. You are receiving this because you authored the thread.Message ID: @.***>

calebweinreb commented 1 year ago

You didn't paste an error message but I have a guess about what it is based on continuing the tutorial using your data. I'll fix the error in the next release. For now you can get around it by setting plot_every_n_iters to 0:

model, history, name = kpms.fit_model(model, data, labels, ar_only=True, 
                                      num_iters=50, project_dir=project_dir, plot_every_n_iters=0)

The error likely reflects the fact that your recordings are less than 600 frames long. Is that correct? It's best to include a few hours of data when modeling, otherwise the results won't be great.

juliagorman commented 1 year ago

Oh yeah okay so would it work better if I ran the video off a bunch of short clips in one directory or should I upload a bunch of larger videos?

JC Gorman PhD student | Millerhttps://millerlab.ucsd.edu/ lab Neurosciences Graduate Program | UCSD


From: Caleb Weinreb @.> Sent: Saturday, May 6, 2023 5:20 AM To: dattalab/keypoint-moseq @.> Cc: Julia C Gorman @.>; Author @.> Subject: Re: [dattalab/keypoint-moseq] "ValueError: cannot reshape array of size 0 into shape (0,newaxis)" when loading data (Issue #36)

You didn't paste an error message but I have a guess about what it is based on continuing the tutorial using your data. I'll fix the error in the next release. For now you can get around it by setting plot_every_n_iters to 0:

model, history, name = kpms.fit_model(model, data, labels, ar_only=True, num_iters=50, project_dir=project_dir, plot_every_n_iters=0)

The error likely reflects the fact that your recordings are less than 600 frames long. Is that correct? It's best to include a few hours of data when modeling, otherwise the results won't be great.

— Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https://github.com/dattalab/keypoint-moseq/issues/36*issuecomment-1537130412__;Iw!!Mih3wA!CR0HbkDI-1la_5YsRhHd6z-1ViKLv1xWhXg7yZ4zBi29KcspefPdK2iUHcXlnppzVzzA8aHEdCNRBMirccGXTuTOQA$, or unsubscribehttps://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AHXPYCKEMNKSAPLO5TS5SM3XEY6YFANCNFSM6AAAAAAXWFV4TM__;!!Mih3wA!CR0HbkDI-1la_5YsRhHd6z-1ViKLv1xWhXg7yZ4zBi29KcspefPdK2iUHcXlnppzVzzA8aHEdCNRBMirccEX-SUwvA$. You are receiving this because you authored the thread.Message ID: @.***>

calebweinreb commented 1 year ago

I mean it depends... are the short clips fundamentally different from the long videos? Assuming all the data include the same set of keypoints for animals of roughly the same size recorded in similar environments, then I would just include all the data you have. The more the better.