yitu-opensource / MobileNeXt

Other
147 stars 28 forks source link

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

Open DLPerf opened 1 year ago

DLPerf commented 1 year ago

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 commented 1 year ago

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