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
273 stars 137 forks source link

Impossible to extract features in Multi Animal Tracking #236

Open Lucas97223 opened 1 year ago

Lucas97223 commented 1 year ago

Describe the bug I'm working with multi animal tracking from DLC from h5 files

To Reproduce Steps to reproduce the behavior:

  1. Go to Load Project and load one
  2. Click on the Extract Features tab
  3. Click on Extract features
  4. See error : "Exception in thread Thread-72: Traceback (most recent call last): File "C:\Users\Admin\anaconda3\envs\S\lib\threading.py", line 980, in _bootstrap_inner self.run() File "C:\Users\Admin\anaconda3\envs\S\lib\threading.py", line 917, in run self._target(*self._args, self._kwargs) File "C:\Users\Admin\anaconda3\envs\S\lib\site-packages\simba\SimBA.py", line 2258, in extractfeatures feature_extractor.extract_features() File "C:\Users\Admin\anaconda3\envs\S\lib\site-packages\simba\features_scripts\feature_extractor_16bp.py", line 138, in extract_features self.out_data['Mouse_1_poly_area'] = Parallel(n_jobs=-1, verbose=0, backend="threading")(delayed(self.convex_hull_calculator_mp)(x, self.px_per_mm) for x in mouse_1_ar) File "C:\Users\Admin\anaconda3\envs\S\lib\site-packages\joblib\parallel.py", line 1098, in call self.retrieve() File "C:\Users\Admin\anaconda3\envs\S\lib\site-packages\joblib\parallel.py", line 975, in retrieve self._output.extend(job.get(timeout=self.timeout)) File "C:\Users\Admin\anaconda3\envs\S\lib\multiprocessing\pool.py", line 771, in get raise self._value File "C:\Users\Admin\anaconda3\envs\S\lib\multiprocessing\pool.py", line 125, in worker result = (True, func(*args, *kwds)) File "C:\Users\Admin\anaconda3\envs\S\lib\site-packages\joblib_parallel_backends.py", line 620, in call return self.func(args, kwargs) File "C:\Users\Admin\anaconda3\envs\S\lib\site-packages\joblib\parallel.py", line 288, in call return [func(*args, *kwargs) File "C:\Users\Admin\anaconda3\envs\S\lib\site-packages\joblib\parallel.py", line 288, in return [func(args, **kwargs) File "C:\Users\Admin\anaconda3\envs\S\lib\site-packages\simba\features_scripts\feature_extractor_16bp.py", line 99, in convex_hull_calculator_mp return ConvexHull(arr).area / px_per_mm File "_qhull.pyx", line 2458, in scipy.spatial._qhull.ConvexHull.init File "_qhull.pyx", line 353, in scipy.spatial._qhull._Qhull.init scipy.spatial._qhull.QhullError: QH6154 Qhull precision error: Initial simplex is flat (facet 1 is coplanar with the interior point)

While executing: | qhull i Qt Options selected for Qhull 2019.1.r 2019/06/21: run-id 1840749349 incidence Qtriangulate _pre-merge _zero-centrum _max-width 4.2e+02 Error-roundoff 3.4e-13 _one-merge 1.7e-12 _near-inside 8.4e-12 Visible-distance 6.7e-13 U-max-coplanar 6.7e-13 Width-outside 1.3e-12 _wide-facet 4e-12 _maxoutside 2e-12

The input to qhull appears to be less than 2 dimensional, or a computation has overflowed.

Qhull could not construct a clearly convex simplex from points:

The center point is coplanar with a facet, or a vertex is coplanar with a neighboring facet. The maximum round off error for computing distances is 3.4e-13. The center point, facets and distances to the center point are as follows:

center point 39.32 140.7

facet p7 p0 distance= -7.1e-15 facet p6 p0 distance= -18 facet p6 p7 distance= -7.1e-15

These points either have a maximum or minimum x-coordinate, or they maximize the determinant for k coordinates. Trial points are first selected from points that maximize a coordinate.

The min and max coordinates for each dimension are: 0: 3.027e-27 117.9 difference= 117.9 1: 5.558e-27 422 difference= 422

If the input should be full dimensional, you have several options that may determine an initial simplex:

If the input is lower dimensional:

Expected behavior I expect to have the features_extracted folder in my project folder, which works when I select Simple Tracking, but i need to do it for Multi Animal Tracking

Desktop (please complete the following information):

sronilsson commented 1 year ago

Hello @Lucas97223! Which version of SImBA are you working with? pip show simba-uw-tf-dev

sronilsson commented 1 year ago

There is more information on this error here: however, there was a fix for this error inserted fairly recently:

https://github.com/sgoldenlab/simba/blob/master/docs/FAQ.md#3-i-get-a-qhull-eg-qh6154-or-6013-error-when-extracting-the-features

Lucas97223 commented 1 year ago

Hi, thank you for your very quick answer. I'm currently using the version 1.50.1 of Simba. Tahnk you, I'll take a look at the link you sent

Lucas97223 commented 1 year ago

Hi again, I read the issue solution from the link and thought about it. First of all, no body-part locations were filtered in the pose-estimation performed via DLC, so the second option of the solution is not checked in my situation. Regarding, the first option, the fact that the animals disappear sometimes is very important in my experiments. My arena contains a nest and when the mice enter in it, they disappear and that is a very important information that we don't want to loose. Considering your solution, the only way that I solve the problem is to interpolate the pose estimation data. This is a good idea but the problem is that the mice can spend a lot of time in the nest. Hence, for them not to disappear, I would have to set a very long period for the interpolation and I am afraid it is going to mess with the data when the mice are actually visible by the camera. Do you have an idea of how I could do to solve this problem? If not, I think the best thing to do is to run the nest analysis as if it was a classical traking situation, and analyse the other data by removing the moments they are in the nest. This solution still makes me loose a lot of data. Thank you in advance!

sronilsson commented 1 year ago

Got it.

TLDR: can you update to simba 1.52.4 with pip install simba-uw-tf-dev --upgrade and see if it works?

The error comes from being unable to calculate the volume of the animals. I thought it was because all the body-parts landed on the same coordinate (the animal is one-dimensional), and was surprised, as we should catch 1D events now and set the animal volume to 0. However I looked back at your error and that does not seem to be it - you seem to have sub-pixel data with body-parts landing on eg pixel 1.8e-25 and pixel 4.2e-25 and I am guessing scipy.spatial.ConvexHull struggle with these values. I've inserted a fix where the values are turned to ints before trying to calculate hull.

Lucas97223 commented 1 year ago

Hi, Thank you for such quick replies. After upgrading simba, I still have the same error message or very similar:

While executing: | qhull i Qt Options selected for Qhull 2019.1.r 2019/06/21: run-id 206061243 incidence Qtriangulate _pre-merge _zero-centrum _max-width 5.3e+02 Error-roundoff 4.5e-13 _one-merge 2.3e-12 _near-inside 1.1e-11 Visible-distance 9e-13 U-max-coplanar 9e-13 Width-outside 1.8e-12 _wide-facet 5.4e-12 _maxoutside 2.7e-12

The input to qhull appears to be less than 2 dimensional, or a computation has overflowed.

Qhull could not construct a clearly convex simplex from points:

The center point is coplanar with a facet, or a vertex is coplanar with a neighboring facet. The maximum round off error for computing distances is 4.5e-13. The center point, facets and distances to the center point are as follows:

center point 78.33 176

facet p7 p0 distance= -1.4e-14 facet p1 p0 distance= -1.8e+02 facet p1 p7 distance= -1.4e-14

These points either have a maximum or minimum x-coordinate, or they maximize the determinant for k coordinates. Trial points are first selected from points that maximize a coordinate.

The min and max coordinates for each dimension are: 0: 0 235 difference= 235 1: 0 528 difference= 528

If the input should be full dimensional, you have several options that may determine an initial simplex:

If the input is lower dimensional:

Thank you in advance

sronilsson commented 1 year ago

Thanks for testing @Lucas97223 - could you drop the CSV for the video that errors from the project_folder/csv/outlier_corrected_movement_location here and I will take a look? If too large then try zip or gdrive link? Thanks!

Lucas97223 commented 1 year ago

Please fin attached the link for the csv file for the right video: https://drive.google.com/drive/folders/1NjKU89mUKrBSw_Uly5o762jEtGZz6eOD?usp=sharing

sronilsson commented 1 year ago

Thanks for sharing @Lucas97223, very helpful, inserted a fix when scipy.spatial.ConvexHull can't handle the numbers. Will push it later and let you know. PS. The video is more than half a million frames, so took me nearly 30min to extract features from that file on my i5

Lucas97223 commented 1 year ago

Ok, thank you very much for your help and availability! I know it is very long (the others will be 12h long, so double of the one I shared). Have a nice day

sronilsson commented 1 year ago

👍🏻 Can you test how it looks after pip install simba-uw-tf-dev --upgrade and let me know how it goes?

Lucas97223 commented 1 year ago

Hi again, I think this version runs correctly with my data. I did not run the whole process of extracting features but it seems to work. I will do it in two days and let you know: Thank for everything

Lucas97223 commented 1 year ago

Hi, I just ran the extraction of the features on my Multi Animal Tracking data and it worked! Thank you very much for your help.

Lucas97223 commented 1 year ago

Hi again, I just want to signal to changes that I spotted using the aforementioned version of simba (1.52.5). First one that does not seem a problem to me: the graphic interface of this version has changed when loading a project in the [Further imports] tab. Second one is an issue for me: since I upgraded simba, the ROI analysis is not performed anymore on the ROI design thanks to the "polygon" shape. The quantifications do not appear in the files created via ANALYZE ROI DATA. Could it be a problem with the new version or is it an other problem independent to that ? Thanks in advance

sronilsson commented 1 year ago

Hi @Lucas97223 - again, thanks for reporting! I tried to recreate it but it worked fine on my end so need a little more info.

Which button is it that you are using, is it the button in the screengrab below?

About the [further imports] tab: yes, I realized all the buttons and windows where floating around un-aligned and looked a little crazy, they have just but put in their own frame.

image
Lucas97223 commented 1 year ago

Yeah I use this button, it also doesn't work when I append the ROI features to the other features, but I guess it is a consequence of the first problem.

sronilsson commented 1 year ago

What error do you get when you append ROI features?

Can you see if the errors persist in 1.52.7, if it does I can dig?

Lucas97223 commented 1 year ago

I have no error during the process, either for ROI analysis or for appending ROI data to features_extracted. I just tried with the updated version but it did not work either.

sronilsson commented 1 year ago

Got it, does the project still live in that gdrive link, or do you have a new one you are working with?

Lucas97223 commented 1 year ago

It is a new one. New project but same video.

sronilsson commented 1 year ago

Could you place the new one in the same gdrive and I can see if I can replicate the error on my end with your project?

Lucas97223 commented 1 year ago

I put the config.ini file in the folder because i don't have enough place to put all the project. Is it enough or shall I found another way of sharing the project?

sronilsson commented 1 year ago

Thanks @Lucas97223, but I need more to be able to recreate your error: It's enough with a project with a single file within the project_folder/csv/outlier_corrected_movement_location folder. If you have large video files, or any other large files within the sub-directories within the project/csv subdirectories, then you can skip sharing those.

Lucas97223 commented 1 year ago

Ok, I managed to put the whole project on this gdrive: https://drive.google.com/drive/u/1/folders/1ZGb67uULh4XHOn2UFaDlyJQ1XOuSCwHz

sronilsson commented 1 year ago

Thanks @Lucas97223 ! It looks like you will have to grant access

Lucas97223 commented 1 year ago

Sorry for that. I think it is okay now. Besides, I had another project running with a polygon shape as a test and it has worked well, the ROI analysis is also performed for this shape. Hence, I think that the problem comes from my current project and not with the version. I will just try and re-do the project to see if the problem persists.

sronilsson commented 1 year ago

Thanks, let me know!