Repository navigation
Description
Describe the problem
analyze_videos (PyTorch engine) produces several pickle files per video that are read repeatedly in the multi-animal pipeline. This may lead to inefficient use of memory and data duplication.
- Memory grows linearly with video length with the default
use_shelve=Falsewhere all added predictions are kept in memory and pickled at once after inference. - Data duplication as
_full.pickleand_assemblies.picklebasically hold the same prediction data. - Repeated read as each downstream stage (assemblies, CTD tracking, tracking and stitching) persists its output but next stage reloads the whole pickle files.
Describe solutions you've considered
Some ideas that can be mutually exclusive or inclusive.
use_shelve=Truealready solves memory peak issues during inference as it writes the predictions to disk on-the-fly avoiding to hold all predictions at once in memory. However for now it only covers the inference stage and is disabled for single-animal projects.- Pass data in memory between downstream stages to avoid repeated read while keeping writes for additional downstream access.
- Chunk write and lazy read for example with predictions as dense (frames, animals, bodyparts, 3) arrays and HDF5/Zarr instead of pickle.
- Persist only one structure containing predictions, assemblies and tracklets.
Additional context
| File | Written by | Read by |
|---|---|---|
_full.pickle |
analyze_videos |
_generate_assemblies_file, CTD-tracking in analyze_videos, convert_detections2tracklets |
_meta.pickle |
analyze_videos |
convert_detections2tracklets |
_assemblies.pickle |
_generate_assemblies_file (multi-animal only) |
convert_detections2tracklets, loading conditions if CTD |
_el / _bx / _sk.pickle |
convert_detections2tracklets (multi-animal, auto_track=True) |
stitch_tracklets |
-
Downstream tools also rely on these files so solutions should take these into account :
create_labeled_video,
create_video_with_all_detections,create_video_from_pickled_tracks,
extract_outlier_frames/find_outliers_in_raw_data, the tracklet refinement GUI,
transformer_reID, and re-running tracking/stitching with different parameters
without re-running GPU inference. -
LoadFullMultiAnimalcould be removed -
Reading order when multiple pickle/shelf files coexist. For example in
find_video_full_dataofutils
Activity
[-]Refactor pickling/data manipulation in video inference[/-][+]Refactor data pickling/manipulation in video inference[/+][-]Refactor data pickling/manipulation in video inference[/-][+]Refactor data pickling/manipulation in analyze_videos[/+]