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
297 stars 143 forks source link

Problem analyzing ROI data Aggregates #358

Open Monica9577 opened 6 months ago

Monica9577 commented 6 months ago

Describe the bug After upgrading to the new version of SIMBA (1.90.7), when I tried to redo some ROI analyses, I got the error that I copy at the end. I tried to redo the project from 0 and I still get the same error. Error: Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\Usuario\anaconda3\envs\simba-latest\lib\tkinter__init.py", line 1705, in call__ return self.func(*args) File "C:\Users\Usuario\anaconda3\envs\simba-latest\lib\site-packages\simba\mixins\pop_up_mixin.py", line 308, in self.run_frm, text=title, fg="blue", command=lambda: run_function() File "C:\Users\Usuario\anaconda3\envs\simba-latest\lib\site-packages\simba\ui\pop_ups\roi_analysis_pop_up.py", line 104, in run roi_analyzer.run() File "C:\Users\Usuario\anaconda3\envs\simba-latest\lib\site-packages\simba\roi_tools\ROI_analyzer.py", line 186, in run location_2=np.array([center_x, center_y]), TypeError: not enough arguments: expected at least 3, got 2

To Reproduce Steps to reproduce the behavior:

  1. simba
  2. roi window 3.click on analyse roi data: aggregates
  3. See error

Expected behavior Usually it runs the analysis and then creates the csv file with the ROI data

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

sronilsson commented 6 months ago

Thanks @Monica9577 - Can you do me a massive favor and share your /project_folder/logs/measures/ROI_definitions.h5 file with me?

I was just looking at this the other day but appears to have some issues with circles not beeing stored correctly.

Monica9577 commented 6 months ago

Of course, here it goes!

ROI_definitions.zip

sronilsson commented 6 months ago

@Monica9577 - thanks! Let me know how it looks like with circles in version 1.90.8, after updating.

Monica9577 commented 6 months ago

Good morning After upgrading to the latest version it now allows me to analyze the ROI, however, when checking the final video, you can see how at a specific moment of the video there is a cut (which is not in the original video) and from there it starts to count a “ghost” animal.

I send you the original video and the video generated by simba. This cut can be seen at the second 1:25

After checking both videos, I have seen that the results would be correct, since the position estimates that are tracked correspond to the original animal.

Monica9577 commented 6 months ago

I'm attaching the videos I commented on github, as they are too big to send them via github. NOR ENCODING FExMP8 ROI.zip https://drive.google.com/file/d/1XfAnO3DOgklq2PJuF0yVNXQQ0DDz0fyA/view?usp=drive_web

https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail Libre de virus.www.avast.com https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

El vie, 26 abr 2024 a las 13:37, Simon Nilsson @.***>) escribió:

@Monica9577 https://github.com/Monica9577 - thanks! Let me know how it looks like with circles in version 1.90.8, after updating.

— Reply to this email directly, view it on GitHub https://github.com/sgoldenlab/simba/issues/358#issuecomment-2079215444, or unsubscribe https://github.com/notifications/unsubscribe-auth/BGGCRMMI7RT4MJEVG3E6LNTY7I36PAVCNFSM6AAAAABG2PXEDCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZZGIYTKNBUGQ . You are receiving this because you were mentioned.Message ID: @.***>

Monica9577 commented 6 months ago

Hi again,

After checking the results csv, it seems is only analyzing the first video and not all of them

sronilsson commented 6 months ago

Thanks @Monica9577 - I made a lot of changes over the beginning of the week, and it sounds like a few bugs sneaked it. I appreciate your help and I will get them fixed and get back to you.

sronilsson commented 6 months ago

I've requested access to the Gdrive file @Monica9577

Monica9577 commented 6 months ago

Yes, I have approved the request

El dom, 28 abr 2024 21:28, Simon Nilsson @.***> escribió:

I've requested access to the Gdrive file @Monica9577 https://github.com/Monica9577

— Reply to this email directly, view it on GitHub https://github.com/sgoldenlab/simba/issues/358#issuecomment-2081613990, or unsubscribe https://github.com/notifications/unsubscribe-auth/BGGCRMMH5OBZTWS45KWWM7LY7VEVTAVCNFSM6AAAAABG2PXEDCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBRGYYTGOJZGA . You are receiving this because you were mentioned.Message ID: @.***>

sronilsson commented 6 months ago

Nice! I found the issue about the missing ROI CSV data. If you update to the latest version, how does it look on your end?

For the visualization, I can see the problem in your videos (thank you for sharing) but I cannot recreate it on my end. Can you share with me a screenshot of how your selections look like in the ROi visualization pop-up menu before you click to run the visualization?

Monica9577 commented 6 months ago

The csv is perfect now :)

About the screenshot Here it goes ! (I'm still having the same problem with the generated videos in the new version) [image: image.png]

https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail Libre de virus.www.avast.com https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail <#m_3491437334582741493_m_5200625503861592641_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

El dom, 28 abr 2024 a las 21:43, Simon Nilsson @.***>) escribió:

Nice! I found the issue about the missing ROI CSV data. If you update to the latest version, how does it look on your end?

For the visualization, I can see the problem in your videos (thank you for sharing) but I cannot recreate it on my end. Can you share with me a screenshot of how your selections look like in the ROi visualization pop-up menu before you click to run the visualization?

— Reply to this email directly, view it on GitHub https://github.com/sgoldenlab/simba/issues/358#issuecomment-2081626496, or unsubscribe https://github.com/notifications/unsubscribe-auth/BGGCRMITPUM7BDC6EIANOS3Y7VGOJAVCNFSM6AAAAABG2PXEDCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBRGYZDMNBZGY . You are receiving this because you were mentioned.Message ID: @.***>

sronilsson commented 6 months ago

Good about the CSV! But I can't see the screengrab for some reason.

sronilsson commented 6 months ago

... possibly because the screenshot image has been attached to an email rather than in the GitHub issue thread?

Monica9577 commented 6 months ago

Captura de pantalla 2024-04-28 215221

sronilsson commented 6 months ago

Ah it's "ROI features".. thank you let me try that.

sronilsson commented 6 months ago

Hi @Monica9577 - can you let me know if you still see the issue in the ROI feature visualization in version 1.91.5 ?

I can't reproduce the error, but I can see how it is possible for it to happen earlier if the index of the file /project_folder/csv/outlier_corrected_movement_location/NOR ENCODING FExMP8.csv was not sequential or it contained duplicates values in the index.

If it is still causing an issue, would you mind sharing the /project_folder/csv/outlier_corrected_movement_location/NOR ENCODING FExMP8.csv file with me?

Thanks! Simon

Monica9577 commented 6 months ago

Yes, unfortunately it's not working ... I'm sending you the corrected location csv

Thanks in advance NOR ENCODING FExMP8.csv

sronilsson commented 6 months ago

I did a super quick dirty test - but I just can't see the jump between the video and tracking data :( https://drive.google.com/file/d/1xSvjJpxgBrgNmdxFlODjYJOMfrG_olLi/view?usp=sharing

Can you do me one favor and just check which version of SimBA you have with pip show simba-uw-tf-dev and paste me what you see printed?

Monica9577 commented 6 months ago

Name: Simba-UW-tf-dev Version: 1.91.5 Summary: Toolkit for computer classification of behaviors in experimental animals Home-page: https://github.com/sgoldenlab/simba Author: Simon Nilsson, Jia Jie Choong, Sophia Hwang Author-email: @.*** License: GNU Lesser General Public License v3 (LGPLv3) Location: c:\users\monip\anaconda3\envs\new_simba\lib\site-packages Requires: joblib, geos, dash-colorscales, pandas, scipy, dash-color-picker, h5py, imblearn, numba, shap, shapely, graphviz, tqdm, imutils, eli5, pyarrow, tables, matplotlib, seaborn, ffmpeg-python, statsmodels, cefpython3, plotly, dash, imgaug, yellowbrick, xlrd, kaleido, scikit-image, trafaret, pyyaml, dtreeviz, xgboost, scikit-learn, dash-html-components, numpy, psutil, Pillow, numexpr, tabulate, dash-core-components, opencv-python Required-by:

I did everything again and stil happening... Either with square or circle ROIs. I also tried with another set of videos, and I have the same problem.

Also this error warning appears when creating the ROI features video

SIMBA WARNING: FrameRangeWarning: The video E:/SIMBA/PROJECTS\NOR_Circle_PUPS_Trial\project_folder\videos\NOR ENCODING FExMP8.mp4 has 18000 frames, but the associated data file for this video has 18001 rows

https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail Libre de virus.www.avast.com https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

El lun, 6 may 2024 a las 20:42, Simon Nilsson @.***>) escribió:

I did a super quick dirty test - but I just can't see the jump between the video and tracking data :( https://drive.google.com/file/d/1xSvjJpxgBrgNmdxFlODjYJOMfrG_olLi/view?usp=sharing

Can you do me one favor and just check which version of SimBA you have with pip show simba-uw-tf-dev and paste me what you see printed?

— Reply to this email directly, view it on GitHub https://github.com/sgoldenlab/simba/issues/358#issuecomment-2096677492, or unsubscribe https://github.com/notifications/unsubscribe-auth/BGGCRMNMIGGIJOPR6RRAQGTZA7FIBAVCNFSM6AAAAABG2PXEDCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJWGY3TONBZGI . You are receiving this because you were mentioned.Message ID: @.***>

sronilsson commented 6 months ago

Thanks @Monica9577 for testing - I will take another look tomorrow to see how this could possibly happen

sronilsson commented 6 months ago

@Monica9577 - good news is that I was able to recreate this issue when I ran it on a PC instead of my Mac.. not I just have to figure out why that is the case... :)

sronilsson commented 6 months ago

For whatever reason, it is some frames e.g., frame 15429 in the video NOR ENCODING FExMP8.mp4 that does not read in properly on PC, so it brakes, while it reads in fine on Mac. Pretty odd, anyway, will continoue digging.

sronilsson commented 6 months ago

@Monica9577 The problem is that in your video files, we could not reliably read some specific frames when on a PC. E.g., when SimBA tried to grab frame 15429 and draw your ROIs and body-parts etc on it, nothing came back, and it silently errored out (it was kind of hard to see as it is soo much printed out when multiprocessing).

To fix it, I used this menu below to "re-encode" your videos, basically converting your NOR ENCODING FExMP8.mp4 into a new mp4 file, and then I used that new MP4 file in the SimBA project, and then it worked on a PC.

Can you let me know if that fixes it on your end?

image
Monica9577 commented 5 months ago

I converted the video to avi and then to mp4 (it didn't let me converte it from mp4 to mp4) and use that video in the same project. I didn't work Then I created the project from the beginning. Then, this error showed up:

Exception in Tkinter callback multiprocessing.pool.RemoteTraceback: """ Traceback (most recent call last): File "C:\Users\monip\anaconda3\envs\NEW_SIMBA\lib\site-packages\pandas\core\indexes\range.py", line 376, in get_loc return self._range.index(new_key) ValueError: 18000 is not in range

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\monip\anaconda3\envs\NEW_SIMBA\lib\multiprocessing\pool.py", line 119, in worker result = (True, func(*args, **kwds)) File "C:\Users\monip\anaconda3\envs\NEW_SIMBA\lib\site-packages\simba\plotting\ROI_feature_visualizer_mp.py", line 89, in _roi_feature_visualizer_mp bp_cords = data_df.loc[current_frm, list(bp)].values.astype(np.int64) File "C:\Users\monip\anaconda3\envs\NEW_SIMBA\lib\site-packages\pandas\core\indexing.py", line 1418, in getitem return self._getitem_tuple(key) File "C:\Users\monip\anaconda3\envs\NEW_SIMBA\lib\site-packages\pandas\core\indexing.py", line 805, in _getitem_tuple return self._getitem_lowerdim(tup) File "C:\Users\monip\anaconda3\envs\NEW_SIMBA\lib\site-packages\pandas\core\indexing.py", line 929, in _getitem_lowerdim section = self._getitem_axis(key, axis=i) File "C:\Users\monip\anaconda3\envs\NEW_SIMBA\lib\site-packages\pandas\core\indexing.py", line 1850, in _getitem_axis return self._get_label(key, axis=axis) File "C:\Users\monip\anaconda3\envs\NEW_SIMBA\lib\site-packages\pandas\core\indexing.py", line 160, in _get_label return self.obj._xs(label, axis=axis) File "C:\Users\monip\anaconda3\envs\NEW_SIMBA\lib\site-packages\pandas\core\generic.py", line 3737, in xs loc = self.index.get_loc(key) File "C:\Users\monip\anaconda3\envs\NEW_SIMBA\lib\site-packages\pandas\core\indexes\range.py", line 378, in get_loc raise KeyError(key) KeyError: 18000 """

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "C:\Users\monip\anaconda3\envs\NEW_SIMBA\lib\tkinter__init.py", line 1705, in call__ return self.func(*args) File "C:\Users\monip\anaconda3\envs\NEW_SIMBA\lib\site-packages\simba\ui\pop_ups\roi_features_plot_pop_up.py", line 152, in command=lambda: self.run(multiple=False), File "C:\Users\monip\anaconda3\envs\NEW_SIMBA\lib\site-packages\simba\ui\pop_ups\roi_features_plot_pop_up.py", line 247, in run threading.Thread(target=roi_feature_visualizer.run()).start() File "C:\Users\monip\anaconda3\envs\NEW_SIMBA\lib\site-packages\simba\plotting\ROI_feature_visualizer_mp.py", line 380, in run for cnt, result in enumerate(pool.imap(constants, frame_range, chunksize=self.multiprocess_chunksize)): File "C:\Users\monip\anaconda3\envs\NEW_SIMBA\lib\multiprocessing\pool.py", line 735, in next raise value KeyError: 18000

Also this error shows up in the main simba window: SIMBA WARNING: FrameRangeWarning: The video E:/SIMBA/PROJECTS\nor_trial\project_folder\videos\NOR ENCODING FExMP8.mp4 has 18002 frames, but the associated data file for this video has 18000 rows ❗️ Creating ROI feature images, multiprocessing (chunksize: 1, cores: 7)... Batch core 1/7 complete... Batch core 2/7 complete... Batch core 3/7 complete... Batch core 4/7 complete... Batch core 5/7 complete... Batch core 6/7 complete...

Monica9577 commented 5 months ago

Hi Again

I just re-analyzed the video in dlc and run the project again, and it worked for me

sronilsson commented 5 months ago

Hi @Monica9577 thanks for letting me know.

FYI I know the video format conversion is clunky (e.g., as you say you can't convert/change mp4->MP4). However, I'm working on making the menus more flexible, they were written 4 years ago, should be done next week.