mtcnn icon indicating copy to clipboard operation
mtcnn copied to clipboard

Multiple detection and tf.function retracing

Open pasqLisena opened this issue 5 years ago • 3 comments

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?

pasqLisena avatar Mar 09 '20 17:03 pasqLisena

Same Here. Any Help??

manoharsaialapati avatar Sep 19 '20 15:09 manoharsaialapati

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.

alexkyllo avatar Nov 01 '20 05:11 alexkyllo

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.

DAlkemade avatar Sep 27 '21 16:09 DAlkemade