fixed a bug
This commit is contained in:
@@ -15,18 +15,30 @@ except ImportError:
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
class VideoCleaner:
|
class VideoCleaner:
|
||||||
def __init__(self, model_path='yolo26n.pt', brightness_threshold=25, age_days=30):
|
def __init__(self, model_path='yolo26n.pt', brightness_threshold=25, age_days=30, workers=4):
|
||||||
print(f"Initializing YOLO model: {model_path}...")
|
self.model_path = model_path
|
||||||
try:
|
|
||||||
self.model = YOLO(model_path)
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Failed to load YOLO model: {e}")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
self.brightness_threshold = brightness_threshold
|
self.brightness_threshold = brightness_threshold
|
||||||
self.age_limit = timedelta(days=age_days)
|
self.age_limit = timedelta(days=age_days)
|
||||||
|
self.workers = workers
|
||||||
self.supported_extensions = ('.mp4', '.avi', '.mov', '.mkv', '.flv', '.wmv')
|
self.supported_extensions = ('.mp4', '.avi', '.mov', '.mkv', '.flv', '.wmv')
|
||||||
|
|
||||||
|
# We'll initialize the model inside each process for thread/process safety
|
||||||
|
self.model = None
|
||||||
|
|
||||||
|
def _get_model(self):
|
||||||
|
"""Lazy initialization of the model for each process."""
|
||||||
|
if self.model is None:
|
||||||
|
# print(f"[{os.getpid()}] Initializing YOLO model: {self.model_path}...")
|
||||||
|
try:
|
||||||
|
self.model = YOLO(self.model_path)
|
||||||
|
# Ensure it's on GPU if available
|
||||||
|
if torch.cuda.is_available():
|
||||||
|
self.model.to('cuda')
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Failed to load YOLO model in process {os.getpid()}: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
return self.model
|
||||||
|
|
||||||
def is_frame_color_and_bright(self, frame):
|
def is_frame_color_and_bright(self, frame):
|
||||||
"""Checks if a single frame is in 'Day/Lights-on' mode."""
|
"""Checks if a single frame is in 'Day/Lights-on' mode."""
|
||||||
# 1. Brightness check
|
# 1. Brightness check
|
||||||
|
|||||||
Reference in New Issue
Block a user