Skip to content

Conversation

@tankchenggeng
Copy link

📝 What does this PR do?

This PR introduces a major refactor of the estimate_ose module in video2motion.py to address critical memory and performance limitations:

  1. Generator for Lazy Loading: Replaces the list used for loading images to the device (GPU) with a generator.
  2. Chunk Processing: Implements a chunking mechanism to process data_chunks in smaller, manageable batches.

🚫 Motivation and Context

  • GPU Memory Overflow (OOM): The original code loaded all video frames into GPU memory at once ([frame.to(device) for frame in all_frames]), causing CUDA Out Of Memory errors with longer videos.
  • Exponential Time Complexity: The processing time of the original algorithm scaled poorly with input size, making long video processing times impractical.

These changes transform the resource usage from being a function of the total video length to a function of the processing batch size.

🔧 Changes Made

File Modified: video2motion.py

Specific Changes:

  1. Generator Expression:

    • func(images_crop): Used a generator expression.
  2. Chunk Processing Logic:

    • Refactored the processing loop to break down the input data_chunks into smaller, fixed-size batches.
    • This prevents the algorithm from processing excessively large amounts of data in a single operation, changing the time complexity from exponential to near-linear for the overall video processing task.

🧪 How Has This Been Tested?

  1. Functional Regression Test:
    • Ran the script on a short video (<5s) and verified the output matches the original behavior.
  2. Performance & Stress Test:
    • Processed a long video (>5 minutes) that previously caused an OOM error. The script now completes successfully with manageable memory usage and processing time.
    • Monitored GPU memory usage via nvidia-smi. The memory footprint is now stable and significantly lower throughout the entire process, instead of climbing until a crash.

✅ Checklist

  • My code follows the established code style of this project.
  • I have thoroughly tested my changes, both for correct functionality and performance improvements.
  • This change is a refactor of existing code and does not require documentation updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant