no env variable to set batch mode for mtcnn and opencv

This commit is contained in:
galthran-wq 2025-03-08 15:18:44 +00:00
parent da8f644c79
commit 3111a2895a
2 changed files with 10 additions and 40 deletions

View File

@ -82,32 +82,8 @@ class MtCnnClient(Detector):
return resp return resp
def _supports_batch_detection(self) -> bool: def _supports_batch_detection(self) -> bool:
import mtcnn logger.warning(
import os "Batch detection is disabled for mtcnn by default "
supports_batch_detection = os.getenv( "since the results are not consistent with single image detection. "
"ENABLE_MTCNN_BATCH_DETECTION", "false" )
).lower() == "true" return False
if not supports_batch_detection:
logger.warning(
"Batch detection is disabled for mtcnn by default "
"since the results are not consistent with single image detection. "
"You can force enable it by setting the environment variable "
"ENABLE_MTCNN_BATCH_DETECTION to true."
)
return False
try:
mtcnn_version = mtcnn.__version__
supports_batch_detection = mtcnn_version >= "1.0.0"
except AttributeError:
try:
import mtcnn.metadata
mtcnn_version = mtcnn.metadata.__version__
except AttributeError:
logger.warning("Failed to determine mtcnn version")
logger.warning("Fallback to single image detection")
return False
supports_batch_detection = mtcnn_version >= "1.0.0"
if not supports_batch_detection:
logger.warning("MtCnn version is less than 1.0.0, batch detection is not supported")
logger.warning("Fallback to single image detection")
return supports_batch_detection

View File

@ -33,17 +33,11 @@ class OpenCvClient(Detector):
return detector return detector
def _supports_batch_detection(self) -> bool: def _supports_batch_detection(self) -> bool:
supports_batch_detection = os.getenv( logger.warning(
"ENABLE_OPENCV_BATCH_DETECTION", "false" "Batch detection is disabled for opencv by default "
).lower() == "true" "since the results are not consistent with single image detection. "
if not supports_batch_detection: )
logger.warning( return False
"Batch detection is disabled for opencv by default "
"since the results are not consistent with single image detection. "
"You can force enable it by setting the environment variable "
"ENABLE_OPENCV_BATCH_DETECTION to true."
)
return supports_batch_detection
def detect_faces( def detect_faces(
self, self,