Update utils/__init__.py
Browse files- utils/__init__.py +76 -140
utils/__init__.py
CHANGED
|
@@ -1,160 +1,96 @@
|
|
| 1 |
"""
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
This package provides utility modules for device management, logging,
|
| 6 |
-
configuration, and shared utilities.
|
| 7 |
-
|
| 8 |
-
Author: BackgroundFX Pro Team
|
| 9 |
-
License: MIT
|
| 10 |
"""
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
get_device_manager,
|
| 18 |
-
get_optimal_device,
|
| 19 |
-
fix_cuda_compatibility,
|
| 20 |
-
setup_optimal_threading,
|
| 21 |
-
get_system_diagnostics,
|
| 22 |
-
)
|
| 23 |
|
| 24 |
-
|
| 25 |
-
# Logging (still in utils/logger.py)
|
| 26 |
-
# -----------------------------------------------------------------------------
|
| 27 |
-
from .logger import (
|
| 28 |
-
BackgroundFXLogger,
|
| 29 |
-
setup_logging,
|
| 30 |
-
get_logger,
|
| 31 |
-
log_function_call,
|
| 32 |
-
log_processing_pipeline,
|
| 33 |
-
log_info,
|
| 34 |
-
log_error,
|
| 35 |
-
log_warning,
|
| 36 |
-
log_debug,
|
| 37 |
-
)
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
|
| 41 |
-
# -----------------------------------------------------------------------------
|
| 42 |
-
from .config import (
|
| 43 |
-
ConfigManager,
|
| 44 |
-
ModelConfig,
|
| 45 |
-
QualityConfig,
|
| 46 |
-
ProcessingConfig,
|
| 47 |
-
VideoConfig,
|
| 48 |
-
get_config,
|
| 49 |
-
load_config,
|
| 50 |
-
get_model_config,
|
| 51 |
-
is_model_enabled,
|
| 52 |
-
get_quality_thresholds,
|
| 53 |
-
get_processing_config,
|
| 54 |
-
)
|
| 55 |
|
| 56 |
-
#
|
| 57 |
-
#
|
| 58 |
-
#
|
| 59 |
-
from .monitoring.progress_tracker import ProgressTracker
|
| 60 |
|
| 61 |
-
# -----------------------------------------------------------------------------
|
| 62 |
-
# Shared utilities (from your utilities file at utils/utils.py)
|
| 63 |
-
# -----------------------------------------------------------------------------
|
| 64 |
from .utils import (
|
|
|
|
| 65 |
FileManager,
|
| 66 |
VideoUtils,
|
| 67 |
ImageUtils,
|
| 68 |
ValidationUtils,
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
retry_on_failure,
|
| 73 |
-
batch_process,
|
| 74 |
-
format_duration,
|
| 75 |
-
get_system_info,
|
| 76 |
-
ConfigurationError,
|
| 77 |
-
ValidationError,
|
| 78 |
-
ProcessingError,
|
| 79 |
-
safe_division,
|
| 80 |
-
clamp,
|
| 81 |
-
interpolate,
|
| 82 |
-
moving_average,
|
| 83 |
)
|
| 84 |
|
| 85 |
-
#
|
| 86 |
-
#
|
| 87 |
-
#
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
# Configuration
|
| 112 |
-
"ConfigManager",
|
| 113 |
-
"ModelConfig",
|
| 114 |
-
"QualityConfig",
|
| 115 |
-
"ProcessingConfig",
|
| 116 |
-
"VideoConfig",
|
| 117 |
-
"get_config",
|
| 118 |
-
"load_config",
|
| 119 |
-
"get_model_config",
|
| 120 |
-
"is_model_enabled",
|
| 121 |
-
"get_quality_thresholds",
|
| 122 |
-
"get_processing_config",
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
|
|
|
| 126 |
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
]
|
| 147 |
|
| 148 |
-
#
|
| 149 |
-
#
|
| 150 |
-
#
|
| 151 |
-
try:
|
| 152 |
-
_logger = setup_logging(logs_dir="LOGS")
|
| 153 |
-
_logger.info("✅ BackgroundFX Pro Utils package initialized")
|
| 154 |
|
| 155 |
-
|
| 156 |
-
|
| 157 |
|
| 158 |
-
|
| 159 |
-
except Exception as e:
|
| 160 |
-
print(f"⚠️ Utils package initialization warning: {e}")
|
|
|
|
| 1 |
"""
|
| 2 |
+
BackgroundFX Pro Utils Module
|
| 3 |
+
Provides core utilities and computer vision processing functions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
"""
|
| 5 |
|
| 6 |
+
# Set OMP_NUM_THREADS at module import to prevent libgomp errors
|
| 7 |
+
import os
|
| 8 |
+
if 'OMP_NUM_THREADS' not in os.environ:
|
| 9 |
+
os.environ['OMP_NUM_THREADS'] = '4'
|
| 10 |
+
os.environ['MKL_NUM_THREADS'] = '4'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
import logging
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# Configure module logger
|
| 15 |
+
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
# ============================================================================
|
| 18 |
+
# IMPORTS FROM UTILS.PY
|
| 19 |
+
# ============================================================================
|
|
|
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
from .utils import (
|
| 22 |
+
# Classes
|
| 23 |
FileManager,
|
| 24 |
VideoUtils,
|
| 25 |
ImageUtils,
|
| 26 |
ValidationUtils,
|
| 27 |
+
|
| 28 |
+
# Functions
|
| 29 |
+
get_file_manager,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
)
|
| 31 |
|
| 32 |
+
# ============================================================================
|
| 33 |
+
# IMPORTS FROM CV_PROCESSING.PY
|
| 34 |
+
# ============================================================================
|
| 35 |
+
|
| 36 |
+
from .cv_processing import (
|
| 37 |
+
# Configuration and constants
|
| 38 |
+
PROFESSIONAL_BACKGROUNDS,
|
| 39 |
+
USE_ENHANCED_SEGMENTATION,
|
| 40 |
+
USE_AUTO_TEMPORAL_CONSISTENCY,
|
| 41 |
+
USE_INTELLIGENT_PROMPTING,
|
| 42 |
+
USE_ITERATIVE_REFINEMENT,
|
| 43 |
+
|
| 44 |
+
# Custom exceptions
|
| 45 |
+
SegmentationError,
|
| 46 |
+
MaskRefinementError,
|
| 47 |
+
BackgroundReplacementError,
|
| 48 |
+
|
| 49 |
+
# Main functions
|
| 50 |
+
segment_person_hq,
|
| 51 |
+
segment_person_hq_original,
|
| 52 |
+
refine_mask_hq,
|
| 53 |
+
enhance_mask_opencv_advanced,
|
| 54 |
+
replace_background_hq,
|
| 55 |
+
create_professional_background,
|
| 56 |
+
validate_video_file,
|
| 57 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
# ============================================================================
|
| 60 |
+
# MODULE EXPORTS
|
| 61 |
+
# ============================================================================
|
| 62 |
|
| 63 |
+
__all__ = [
|
| 64 |
+
# From utils.py
|
| 65 |
+
'FileManager',
|
| 66 |
+
'VideoUtils',
|
| 67 |
+
'ImageUtils',
|
| 68 |
+
'ValidationUtils',
|
| 69 |
+
'get_file_manager',
|
| 70 |
+
|
| 71 |
+
# From cv_processing.py
|
| 72 |
+
'PROFESSIONAL_BACKGROUNDS',
|
| 73 |
+
'USE_ENHANCED_SEGMENTATION',
|
| 74 |
+
'USE_AUTO_TEMPORAL_CONSISTENCY',
|
| 75 |
+
'USE_INTELLIGENT_PROMPTING',
|
| 76 |
+
'USE_ITERATIVE_REFINEMENT',
|
| 77 |
+
'SegmentationError',
|
| 78 |
+
'MaskRefinementError',
|
| 79 |
+
'BackgroundReplacementError',
|
| 80 |
+
'segment_person_hq',
|
| 81 |
+
'segment_person_hq_original',
|
| 82 |
+
'refine_mask_hq',
|
| 83 |
+
'enhance_mask_opencv_advanced',
|
| 84 |
+
'replace_background_hq',
|
| 85 |
+
'create_professional_background',
|
| 86 |
+
'validate_video_file',
|
| 87 |
]
|
| 88 |
|
| 89 |
+
# ============================================================================
|
| 90 |
+
# MODULE METADATA
|
| 91 |
+
# ============================================================================
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
+
__version__ = '2.0.0'
|
| 94 |
+
__author__ = 'BackgroundFX Pro Team'
|
| 95 |
|
| 96 |
+
logger.info(f"Utils module v{__version__} initialized successfully")
|
|
|
|
|
|