mediapipe
mediapipe copied to clipboard
How to Completely Suppress Mediapipe and TensorFlow Logs in Python ?
Hello, I am using Mediapipe's Pose module in Python to extract region masks from images. My environment includes VS Code for debugging. Despite my efforts to suppress logs, I am still seeing a significant amount of information printed to the console, including INFO, WARNING, and other messages from Mediapipe and TensorFlow. Here is an excerpt of the problematic log output: INFO: Created TensorFlow Lite XNNPACK delegate for CPU. INFO: Created TensorFlow Lite XNNPACK delegate for CPU. WARNING: All log messages before absl::InitializeLog() is called are written to STDERR W0000 00:00:1731912234.538702 75025 inference_feedback_manager.cc:114] Feedback manager requires a model with a single signature inference. Disabling support for feedback tensors. W0000 00:00:1731912234.624405 75029 landmark_projection_calculator.cc:186] Using NORM_RECT without IMAGE_DIMENSIONS is only supported for the square ROI. Provide IMAGE_DIMENSIONS or use PROJECTION_MATRIX. I have already implemented multiple solutions to suppress the output, including: 1.Setting environment variables: os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' os.environ['GLOG_minloglevel'] = '3' 2.Using Abseil's logging verbosity: from absl import logging as absl_logging absl_logging.set_verbosity(absl_logging.FATAL) 3.Redirecting stdout and stderr during the execution of Mediapipe's code: from contextlib import contextmanager @contextmanager def suppress_all_output(): devnull = open(os.devnull, 'w') old_stdout, old_stderr = sys.stdout, sys.stderr try: sys.stdout, sys.stderr = devnull, devnull yield finally: sys.stdout, sys.stderr = old_stdout, old_stderr devnull.close() Despite these efforts, the logs persist, particularly during the instantiation of Mediapipe's Pose module and subsequent processing steps. My Environment: Operating System: Ubuntu 20.04 Python Version: 3.9 Mediapipe Version: 0.10.18 tensorboard 2.18.0 tensorboard-data-server 0.7.2 tensorboard-plugin-wit 1.8.1 tensorboardX 2.6.2.2 tensorflow-io-gcs-filesystem 0.37.1 Debugger: VS Code Steps to Reproduce: 1.Load an image and process it using Mediapipe's Pose: with mp.solutions.pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5) as pose: results = pose.process(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) 2.Observe the persistent log output in the console. Expected Behavior: No logs should be printed to the console if suppression methods are applied. Actual Behavior: Logs from TensorFlow, Mediapipe, and Abseil persist even after applying the above suppression techniques. Question: Is there a definitive way to completely suppress all logs (including INFO, WARNING, and ERROR) from Mediapipe, TensorFlow, and Abseil without modifying Mediapipe's source code?
Alternatively, if source code modification is required, could you provide detailed guidance on which parts of the Mediapipe source are responsible for logging and how to suppress them effectively?
Thank you for your time and assistance.
Hi @ThomaswellY,
It appears that you are still using the legacy Pose solution, which has been replaced by the upgraded Pose Landmarker Task API. Please note that support for the legacy solution has ended. You can find more details about this change in the legacy guide and available solutions documentation.
We recommend migrating to the new Pose Landmarker Task API, which offers improved features and support. You can review the API overview and follow the Python implementation guide to get started.
If you are still using the legacy solution, you may try the provided workaround here, but please note that further assistance is limited as support for the legacy version has ended. However, if you are using the upgraded API and need help suppressing warning logs, we may be able to assist. please let us know if you need further clarification.
Thank you!!
HI!@kuaashish Thank you for your response and for pointing out the transition to the Pose Landmarker Task API. I have migrated my implementation to the upgraded API, following the Python implementation guide](https://ai.google.dev/edge/mediapipe/solutions/vision/pose_landmarker/python?hl=zh-cn) . However, I am still encountering the issue of persistent log outputs in the console. Despite applying various log suppression techniques, including setting environment variables (TF_CPP_MIN_LOG_LEVEL, GLOG_minloglevel), adjusting Abseil's logging verbosity, and redirecting stdout/stderr during the execution, logs such as the following continue to appear: WARNING: All log messages before absl::InitializeLog() is called are written to STDERR I0000 00:00:1731930035.529357 21253 task_runner.cc:85] GPU suport is not available: INTERNAL: ; RET_CHECK failure (mediapipe/gpu/gl_context_egl.cc:84) egl_initializedUnable to initialize EGL INFO: Created TensorFlow Lite XNNPACK delegate for CPU. W0000 00:00:1731930035.660247 28339 inference_feedback_manager.cc:114] Feedback manager requires a model with a single signature inference. Disabling support for feedback tensors. W0000 00:00:1731930035.831237 28343 inference_feedback_manager.cc:114] Feedback manager requires a model with a single signature inference. Disabling support for feedback tensors. Here is a simplified version of the code that reproduces the issue: import mediapipe as mp import os import cv2 os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' os.environ['GLOG_minloglevel'] = '2' model_path = "/xx/models/mediapipe/pose_landmarker.task" BaseOptions = mp.tasks.BaseOptions PoseLandmarker = mp.tasks.vision.PoseLandmarker PoseLandmarkerOptions = mp.tasks.vision.PoseLandmarkerOptions VisionRunningMode = mp.tasks.vision.RunningMode options = PoseLandmarkerOptions( base_options=BaseOptions(model_asset_path=model_path), running_mode=VisionRunningMode.IMAGE ) with PoseLandmarker.create_from_options(options) as landmarker: image = cv2.imread("example.jpg") mp_image_input = mp.Image.create_from_file("example.jpg") result = landmarker.detect(mp_image_input) Issue: The logs persist during the creation of the PoseLandmarker instance Question: Is there a specific way to suppress these logs (INFO, WARNING, and others) using the Pose Landmarker Task API? I look forward to your suggestions or insights to address this persistent issue. Please let me know if additional details or context are needed.
Thank you for your continued support!
Best regards, ThomaswellY
@kuaashish if any further details are needed, pls let me know , thanks ~
HI @ThomaswellY,
Thank you for the update. Please allow us some time to discuss this with our team, and we will get back to you with an update as soon as possible.
Hi MediaPipe Team.
Thank you for all your hard work on this amazing open source project.
I am encountering the same problem as in this thread, and wanted to add the approaches I have tried, in case it helps:
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' # Suppresses TensorFlow INFO & WARNING logs
os.environ['GLOG_minloglevel'] = '3' # Suppresses GLOG messages (used by MediaPipe)
# Redirect stdout and stderr to suppress MediaPipe logs
class SuppressLogs:
def __enter__(self):
self.stdout = sys.stdout
self.stderr = sys.stderr
sys.stdout = open(os.devnull, 'w')
sys.stderr = open(os.devnull, 'w')
def __exit__(self, exc_type, exc_value, traceback):
sys.stdout.close()
sys.stderr.close()
sys.stdout = self.stdout
sys.stderr = self.stderr
logging.getLogger("mediapipe").setLevel(logging.ERROR) # Suppress INFO and WARNING logs
warnings.filterwarnings("ignore")
with io.capture_output() as captured:
with SuppressLogs():
with PoseLandmarker.create_from_options(options) as landmarker:
...
I still get log messages like the below.
I0000 00:00:1739169268.841851 13200833 gl_context.cc:369] GL version: 2.1 (2.1 Metal - 89.3), renderer: Apple M3 Max W0000 00:00:1739169268.911873 31551203 inference_feedback_manager.cc:114] Feedback manager requires a model with a single signature inference. Disabling support for feedback tensors. W0000 00:00:1739169268.934910 31551203 inference_feedback_manager.cc:114] Feedback manager requires a model with a single signature inference. Disabling support for feedback tensors.
Please let us know an effective method for suppressing log messages.
Thank you.
Hi @whhone,
Could you please look into this issue?
Thank you!!!
Hey folks,
MediaPipe relies fully on absl LOG / glog for logging. So, if:
os.environ['GLOG_minloglevel'] = '3'
doesn't have an effect, please check somehow (e.g. printing in C++) if it was actually applied and try to research why it's so (help is really appreciated here).
Another thing to try experiment with is passing ABSL_MIN_LOG_LEVEL at build time and see if it makes any difference.