sgoldenlab / simba

SimBA (Simple Behavioral Analysis), a pipeline and GUI for developing supervised behavioral classifiers
https://simba-uw-tf-dev.readthedocs.io/
GNU General Public License v3.0
279 stars 138 forks source link

Unreliable ROI quantification #209

Closed DorianBattivelli closed 1 year ago

DorianBattivelli commented 1 year ago

Dear Simba developers,

I'm using Simba-UW-tf-dev, version 0.94.2 from maDLC h5-elispe files. I'm tracking 2 mice simultaneously. I'm facing a strange output in my Detailed_ROI_data file. While I can clearly see my mouse entering a given ROI, it does not appear into my Detailed_ROI_data csv file.

I checked the labeling live on DEEPLABCUT and found that there is neiter ID swap nor missing tracking when the animal enters the ROI. So how is it possible that Simba failes to track the mouse into this ROI? I proceeded to smoothing transformation (300) and to outlier correction with recomanded values (1 for movement / 1.5 for location). Could these steps make some labeling missing for my final analysis? I checked the coordinates in the CSV file, and see no cell with "0" at the time point when the animal occupy the ROI : CSV

However, I'm wandering what does the last column "center_2_p" mean? What is the meaning of the 1?

I wish I could use the "visualize ROI tracking" function to check the signal that Simba analyzes but the program returns the following error when I run the command: Simba-visualize_error

Have you some suggestion to solve this issue? Thank you very much, Best Dorian

sronilsson commented 1 year ago

Hi @DorianBattivelli! Let me see if I can insert something that catches this error with the visualization, so we can see what is going on. My first bet would be that the outlier correction for some reason is to stringent, and body-part locations that should not be corrected has been corrected, hence placing your animal in a different part of the environment than it actually is.

The column center_2_p is for the center body-part of animal 2, and its pose-estimation probability score (as in p). 1 means that the pose-estimation model is 100% certain that is the correct location of the body-part.

DorianBattivelli commented 1 year ago

Also, what I notice is that before and after I run the smoothing correction my Detailed_ROI_data file differed, Before the correction, I found one period when the animal occupied the ROI (even if not at the time I'm mentioning above), while after the correction, this ROI results as never being occupied at all

sronilsson commented 1 year ago

A bit of background: The error you see when trying to visualize the data, comes from SimBA finding multiple ROIs with the same shape for a single video with the same Name. I.e., there are two rectangles named "rectangle_1" in video 1. I don't know how that can sneak in, but I will check it out.

DorianBattivelli commented 1 year ago

It is actually true, for example i have 4 corners in my box 1, since I do not care about each corner per, but only about time spent in whatever corner of this box, I labeled each Corner_box1

sronilsson commented 1 year ago

Alright, SimBA can't group ROIs by name at the moment. I will nevertheless insert a fix that should get around the error but will be a day or so. In the meantime, you could rename them (corner1, corner2..) and it should work.

sronilsson commented 1 year ago

@DorianBattivelli - was easier than I thought. Can you update simbe to 0.95.5 with pip install simba-uw-tf-dev --upgrade and check if you can visualize it now? I inserted a warning when your type of data comes in:

SIMBA WARNING: Some of your ROIs with the same shape has the same names. E.g., you have two rectangles named "My rectangle". SimBA prefers ROI shapes with unique names. SimBA will keep one of the unique shape names and drop the rest

meaning, only one of the corners will be plotted.

DorianBattivelli commented 1 year ago

I just updated, but apparently my SimBA does not work anymore ^^ Schermata 2022-08-22 alle 18 20 07

sronilsson commented 1 year ago

My bad! Hang on @DorianBattivelli

sronilsson commented 1 year ago

@DorianBattivelli can you try again with 0.95.6?

DorianBattivelli commented 1 year ago

Thank you! However, still returning an error when I try to run visualization function: Schermata 2022-08-22 alle 18 31 47

sronilsson commented 1 year ago

haha, alright, another typo... :) hang on.

sronilsson commented 1 year ago

Now we are up to 0.95.7.. can you check for any more typos? :)

DorianBattivelli commented 1 year ago

Thanks! But more typo still needed :) Schermata 2022-08-22 alle 18 44 50

sronilsson commented 1 year ago

This one should be fixed, can you do pip show simba-uw-tf-dev and make sure it reads 0.95.7?

DorianBattivelli commented 1 year ago

Well done, it's working, generqting the video now... thank you, I'll keep you update on what I see.

sronilsson commented 1 year ago

Cheers! 👍 Let me know what you can see.

DorianBattivelli commented 1 year ago

Well, very weird. The tracking is good: we are interesting by the mouse (up-mouse) visiting the corner (Corndown) indicated by the red arrow. And it's good, Up-mouse is tracked into a corner but it's not quantified (unfortunatly I don't see the label of the ROI - but playing the video I see that the entrance of the mouse into this yellow corner does not trigger any ROI).

Another strange fact is that the shape of the central orange square into the lower compartment (shown with purple arrow) has a different shape/location Schermata 2022-08-22 alle 18 58 35

than what I drew: Schermata 2022-08-22 alle 18 59 44

sronilsson commented 1 year ago

Interesting and thanks for reporting! For the missed ROI detection, as there are a few ROIs, is there any chance that there are any other ROI (or multiple ROIs) named CornDown? If you watch the animal enter the other corners, does the counters move as expected? Another possibility is that there is issues when the ROIs are overlapping and I will look into this now..

For the rectangle oddity, there was a bug a couple of months ago, where the bottom right and top left x and y coordinates of the rectangles could be confused when the shapes were modified. But this bug would probably have been seen in the draw interface. I am not sure it is applicable as you may have created the ROIs more recently.

sronilsson commented 1 year ago

No, overlapping ROIs seems to work fine.. could you do me one favor? Re-draw your ROIs in latest SimBA, as a test, and see if it works if you have not done so already?

sronilsson commented 1 year ago

NO need! I was able to replicate it. Lets see if I can figure it out.

sronilsson commented 1 year ago

Got it working on your video, will push an update tomorrow.

DorianBattivelli commented 1 year ago

Amazing, I wait for your update :) Thank you

sronilsson commented 1 year ago

I tested it by drawing your ROIs out from the project you sent me a while back and looks like it should. That said, there are plenty of ROIs, so not all of them can be displayed in in the side bar. SimBA wants to print 72 lines of text and not all can be viewed.

The bad news is that you will have to delete your ROIs in your project, and draw them again for your videos.

Would you mind checking, with version 0.95.8, this time, and let me know if it works?

image

DorianBattivelli commented 1 year ago

Perfect, thank you very much, it will take me a while for drawing ROIs, but I keep you updated once I get data with this new version,

Best

sronilsson commented 1 year ago

Try the duplicate and then rename methods if not already, It can go a lot quicker and ensures ROIs are aligned and the same size.

DorianBattivelli commented 1 year ago

We tried this alreadym the problem is that the prospective is not the same so the distances in the different parts of the plan are not proportional. I'm facing 2 bugs with this last version:

Can you please fix these bugs? Thank you!

sronilsson commented 1 year ago

Will fix! I inserted fixes for the two bullet points as they worked better for me, but I'm on a mac. I will remove as you have issues on Windows.

sronilsson commented 1 year ago

@DorianBattivelli - can you check again with 0.95.9? Fingers crossed!

DorianBattivelli commented 1 year ago

I try it now! Does it mean that SimBA work on mac??

sronilsson commented 1 year ago

Yes, and linux. There is no PC available for me any more so have maintained it on Mac for some months.

DorianBattivelli commented 1 year ago

Very good to know. Now I can draw circles and the drawing window does not change dimension. I visualized the tracking and ROI quanti for 1 video, it seems to work now :) Thank you so much!

sronilsson commented 1 year ago

🚀