ipazc / mtcnn

MTCNN face detection implementation for TensorFlow, as a PIP package.
MIT License
2.19k stars 526 forks source link

Disable progress bars? #121

Open xeb opened 2 years ago

xeb commented 2 years ago

Apologies if this is a Keras or TF issue, but how do I disable the stdout and stderr logging with mtcnn?

Example Class:

#!/usr/bin/env python
""" Face Detection Filter for Progeny """ 
from __future__ import absolute_import
from filter_base import Filter
from mtcnn import MTCNN
import os
import cv2 
import logging

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' 

class FaceDetectFilter(Filter):
    pass

    def __init__(self, threshold=0.70):
        super().__init__()
        self.threshold = threshold
        self.detector = MTCNN()
        return

    def get_faces(self, path):
        img = cv2.cvtColor(cv2.imread(path), cv2.COLOR_BGR2RGB)
        faces = self.detector.detect_faces(img)
        return faces

    def determine_class(self, imgrow):
        faces = self.get_faces(imgrow['thumb_path'])
        if faces is not None and len(faces) > 0:
            for face in faces:
                if face['confidence'] >= self.threshold:
                    return 'face'

        return 'noface'

Results in:

1/1 [==============================] - 0s 15ms/step
1/1 [==============================] - 0s 18ms/step
1/1 [==============================] - 0s 15ms/step
1/1 [==============================] - 0s 15ms/step
1/1 [==============================] - 0s 15ms/step
1/1 [==============================] - 0s 14ms/step
2/2 [==============================] - 0s 2ms/step
1/1 [==============================] - 0s 26ms/step

Logging is disabled but the (tqdm?) progress bars remain. This prevents my own tqdm progress bars from working.

Any ideas?

ladyshen commented 2 years ago

您的邮件已接收!

xeb commented 2 years ago

太感谢了!

sykweon commented 2 years ago

Hello, I'm experiencing the same problem. How did you fix it?

ladyshen commented 2 years ago

您的邮件已接收!

adhoc-research commented 2 years ago

Have the same issue, let me know if anyone finds a solution!

nguyenhoan1988 commented 2 years ago

@amykweon @xeb @equ1 Those loggings are from mtcnn package. You can suppress the logging by editting the mtcnn.py file in ~/miniconda3/envs/<env_name>/lib/<python3.x>/site-packages/mtcnn/mtcnn.py (depends on your package management) or fork this repo: https://github.com/ipazc/mtcnn

Then add verbose=0 to these linse:

Line 410: out = self._pnet.predict(img_y, verbose=0)
Line 410: out = self._rnet.predict(tempimg1, verbose=0)
Line 466: out = self._onet.predict(tempimg1, verbose=0)
ladyshen commented 2 years ago

您的邮件已接收!

AlexandreLamb commented 2 years ago

Line 410: out = self._pnet.predict(img_y, verbose=0) is on Line 342

ladyshen commented 2 years ago

您的邮件已接收!

ladyshen commented 1 year ago

您的邮件已接收!

chj113 commented 11 months ago

I add verbose=0 in lines,but it does not work then I remove tqdm module,it is worked~

ladyshen commented 11 months ago

您的邮件已接收!

colorsolid commented 7 months ago

With newer versions of keras, this has worked for me: import keras keras.utils.disable_interactive_logging() not sure exactly which version added this

ladyshen commented 7 months ago

您的邮件已接收!