ipazc / mtcnn

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

Multiple detection and tf.function retracing #82

Closed pasqLisena closed 3 weeks ago

pasqLisena commented 4 years ago

Hello, I am using MTCNN to extract faces from a big set of images (basically the training set of a face classification system).

My code is more or less like this:

detector = MTCNN()
for img, label, path in zip(data, labels, paths):
        bounding_boxes = detector.detect_faces(img)
        ...

After a few iterations, I receive plenty of warning like this:

W0309 18:16:40.960232 123145478152192 def_function.py:586] 5 out of the last 5 calls to <function _make_execution_function..distributed_function at 0x15b3a78c0> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings is likely due to passing python objects instead of tensors. Also, tf.function has experimental_relax_shapes=True option that relaxes argument shapes that can avoid unnecessary retracing. Please refer to https://www.tensorflow.org/tutorials/customization/performance#python_or_tensor_args and https://www.tensorflow.org/api_docs/python/tf/function for more details.

What can I do?

manoharsaialapati commented 4 years ago

Same Here. Any Help??

alexkyllo commented 4 years ago

This happens when you call the constructor MTCNN() inside a loop (or within a function that you're repeatedly calling). If you move the call to the constructor outside of the loop, the warning will go away.

DAlkemade commented 3 years ago

I only call the constructor once, and this still happens. Anyone have a solution? Converting the input to a tf.Tensor works sometimes, but breaks the function in other cases.