MobileNeXt icon indicating copy to clipboard operation
MobileNeXt copied to clipboard

Performance issue in mobile_deployment/tensorflow/slim/models/research/object_detection/model_lib_v2.py

Open DLPerf opened this issue 2 years ago • 1 comments

Hello! Our static bug checker has found a performance issue in mobile_deployment/tensorflow/slim/models/research/object_detection/model_lib_v2.py: eager_eval_loop is repeatedly called in a for loop, but there is a tf.function decorated function compute_eval_dict defined and called in eager_eval_loop.

In that case, when eager_eval_loop is called in a loop, the function compute_eval_dict will create a new graph every time, and that can trigger tf.function retracing warning.

Here is the tensorflow document to support it.

Briefly, for better efficiency, it's better to use:

@tf.function
def inner():
    pass

def outer():
    inner()  

than:

def outer():
    @tf.function
    def inner():
        pass
    inner()

Looking forward to your reply.

DLPerf avatar Feb 24 '23 02:02 DLPerf

Since there are some variables depending on the outer function, is it necessary? Do you have any good idea? @zhoudaquan @yitutech-opensource

DLPerf avatar Mar 06 '23 02:03 DLPerf