Skip to content

Refactor data pickling/manipulation in analyze_videos #3553

Open

Description

@Ayskin

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=False where all added predictions are kept in memory and pickled at once after inference.
  • Data duplication as _full.pickle and _assemblies.pickle basically 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=True already 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.

  • LoadFullMultiAnimal could be removed

  • Reading order when multiple pickle/shelf files coexist. For example in find_video_full_data of utils

Activity

  1. changed the title [-]Refactor pickling/data manipulation in video inference[/-] [+]Refactor data pickling/manipulation in video inference[/+] on Oct 15, 2026
  2. changed the title [-]Refactor data pickling/manipulation in video inference[/-] [+]Refactor data pickling/manipulation in analyze_videos[/+] on Oct 15, 2026
  3. added
    performance
    on Oct 15, 2026
  4. added theissue type on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

performance

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions