working a bit faster
This commit is contained in:
54
main.py
54
main.py
@@ -475,8 +475,8 @@ def process_segment_with_separate_eyes(segment_info, detector, sam2_processor, m
|
||||
|
||||
return success, left_masks, right_masks
|
||||
|
||||
def main():
|
||||
"""Main processing pipeline."""
|
||||
async def main_async():
|
||||
"""Main processing pipeline with async optimizations."""
|
||||
args = parse_arguments()
|
||||
|
||||
try:
|
||||
@@ -568,6 +568,24 @@ def main():
|
||||
eye_overlap_pixels = config.get('processing.eye_overlap_pixels', 0)
|
||||
enable_greenscreen_fallback = config.get('processing.enable_greenscreen_fallback', True)
|
||||
|
||||
# Initialize async preprocessor if enabled
|
||||
async_preprocessor = None
|
||||
if config.get('advanced.enable_background_lowres_generation', False):
|
||||
from core.async_lowres_preprocessor import AsyncLowResPreprocessor
|
||||
|
||||
max_concurrent = config.get('advanced.max_concurrent_lowres', 3)
|
||||
segments_ahead = config.get('advanced.lowres_segments_ahead', 3)
|
||||
use_ffmpeg = config.get('advanced.use_ffmpeg_lowres', True)
|
||||
|
||||
async_preprocessor = AsyncLowResPreprocessor(
|
||||
max_concurrent=max_concurrent,
|
||||
segments_ahead=segments_ahead,
|
||||
use_ffmpeg=use_ffmpeg
|
||||
)
|
||||
logger.info(f"Async low-res preprocessing: ENABLED (max_concurrent={max_concurrent}, segments_ahead={segments_ahead})")
|
||||
else:
|
||||
logger.info("Async low-res preprocessing: DISABLED")
|
||||
|
||||
if separate_eye_processing:
|
||||
logger.info("VR180 Separate Eye Processing: ENABLED")
|
||||
logger.info(f"Eye overlap pixels: {eye_overlap_pixels}")
|
||||
@@ -578,7 +596,8 @@ def main():
|
||||
config_path=config.get_sam2_config(),
|
||||
vos_optimized=config.get('models.sam2_vos_optimized', False),
|
||||
separate_eye_processing=separate_eye_processing,
|
||||
eye_overlap_pixels=eye_overlap_pixels
|
||||
eye_overlap_pixels=eye_overlap_pixels,
|
||||
async_preprocessor=async_preprocessor
|
||||
)
|
||||
|
||||
# Initialize mask processor with quality enhancements
|
||||
@@ -593,6 +612,16 @@ def main():
|
||||
logger.info("Step 4: Processing segments sequentially")
|
||||
total_humans_detected = 0
|
||||
|
||||
# Start background low-res video preprocessing if enabled
|
||||
if async_preprocessor:
|
||||
logger.info("Starting background low-res video preprocessing")
|
||||
async_preprocessor.start_background_preparation(
|
||||
segments_info,
|
||||
config.get_inference_scale(),
|
||||
separate_eye_processing,
|
||||
current_segment=0
|
||||
)
|
||||
|
||||
# Initialize previous masks for separate eye processing
|
||||
previous_left_masks = None
|
||||
previous_right_masks = None
|
||||
@@ -602,6 +631,15 @@ def main():
|
||||
|
||||
logger.info(f"Processing segment {segment_idx}/{len(segments_info)-1}")
|
||||
|
||||
# Start background preparation for upcoming segments
|
||||
if async_preprocessor and i < len(segments_info) - 1:
|
||||
async_preprocessor.start_background_preparation(
|
||||
segments_info,
|
||||
config.get_inference_scale(),
|
||||
separate_eye_processing,
|
||||
current_segment=i
|
||||
)
|
||||
|
||||
# Reset temporal history for new segment
|
||||
mask_processor.reset_temporal_history()
|
||||
|
||||
@@ -1012,6 +1050,16 @@ def main():
|
||||
except Exception as e:
|
||||
logger.error(f"Pipeline failed: {e}", exc_info=True)
|
||||
return 1
|
||||
finally:
|
||||
# Cleanup async preprocessor if it was used
|
||||
if async_preprocessor:
|
||||
async_preprocessor.cleanup()
|
||||
logger.debug("Async preprocessor cleanup completed")
|
||||
|
||||
def main():
|
||||
"""Main entry point - wrapper for async main."""
|
||||
import asyncio
|
||||
return asyncio.run(main_async())
|
||||
|
||||
if __name__ == "__main__":
|
||||
exit_code = main()
|
||||
|
||||
Reference in New Issue
Block a user