talmolab / sleap

A deep learning framework for multi-animal pose tracking.
https://sleap.ai
Other
436 stars 97 forks source link

Can't export all videos in csv due to memory error #1704

Closed frenchnat closed 7 months ago

frenchnat commented 8 months ago

Bug description

Hi, I get a memory error in Miniforge when trying to export the analysis csv for all my videos (n=71).

Expected behaviour

I would expect to get the analysis csv files for all my videos.

Actual behaviour

I got the analysis csv files for 5 videos then the previously reported error appeared.

Your personal set up

Environment packages ``` # paste output of `pip freeze` or `conda list` here ```
Logs ``` # paste relevant logs here, if any ```

Screenshots

Traceback (most recent call last): File "C:\mambaforge\envs\sleap\lib\site-packages\sleap\gui\app.py", line 499, in lambda: self.commands.exportCSVFile(all_videos=True), File "C:\mambaforge\envs\sleap\lib\site-packages\sleap\gui\commands.py", line 337, in exportCSVFile self.execute(ExportAnalysisFile, all_videos=all_videos, csv=True) File "C:\mambaforge\envs\sleap\lib\site-packages\sleap\gui\commands.py", line 242, in execute command().execute(context=self, params=kwargs) File "C:\mambaforge\envs\sleap\lib\site-packages\sleap\gui\commands.py", line 138, in execute self.do_with_signal(context, params) File "C:\mambaforge\envs\sleap\lib\site-packages\sleap\gui\commands.py", line 162, in do_with_signal cls.do_action(context, params) File "C:\mambaforge\envs\sleap\lib\site-packages\sleap\gui\commands.py", line 1157, in do_action video=video, File "C:\mambaforge\envs\sleap\lib\site-packages\sleap\io\format\csv.py", line 69, in write csv=True, File "C:\mambaforge\envs\sleap\lib\site-packages\sleap\info\write_tracking_h5.py", line 397, in main ) = get_occupancy_and_points_matrices(labels, all_frames, video) File "C:\mambaforge\envs\sleap\lib\site-packages\sleap\info\write_tracking_h5.py", line 122, in get_occupancy_and_points_matrices (frame_count, node_count, 2, track_count), np.nan, dtype=float File "C:\mambaforge\envs\sleap\lib\site-packages\numpy\core\numeric.py", line 343, in full a = empty(shape, dtype, order) numpy.core._exceptions.MemoryError: Unable to allocate 13.8 GiB for an array with shape (54372, 1, 2, 17030) and data type float64

How to reproduce

  1. Go to 'File'
  2. Click on 'Export Analysis CSV...'
  3. Scroll down to 'All Videos...'
  4. See error
roomrys commented 8 months ago

Hi @frenchnat,

The export for pose estimation is a bit clunky in the sense that it tries to allocate space for an array of shape (frame_count, node_count, 2, track_count), populate this array, and then discard any unused portion of the array (i.e. any unused Tracks). You can imagine that since SLEAP doesn't reuse Tracks or automatically delete unused Tracks, this shape can get pretty massive. In your case, you seem to have 17030 Tracks - I doubt all of those are being used.

To get things exporting, I would try deleting all the unused Tracks (in the GUI menubar: Tracks > Delete Multiple > Unused), saving the project as, and retrying.

image

Let us know if that worked.

Thanks, LIezl

frenchnat commented 8 months ago

Hi @roomrys,

Thanks for your reply! It didn't solve the issue because I guess I have too many frames where sleap has tracked instances where there was no animal to track (the videos are not great ahah). I was planning on cleaning the data in the csv files but I guess I need to clean it before exporting then. Would you recommend a way to do this that doesn't require me to manually check every frame of all my videos?

Thanks a lot, Natacha