nicknochnack / RealTimeSignLanguageDetectionwithTFJS

A complete package for building custom real time object detection applications.
116 stars 112 forks source link

Performance issue in Tensorflow/models/research/sequence_projection/sgnn/sgnn.py #4

Open DLPerf opened 1 year ago

DLPerf commented 1 year ago

Hello! Our static bug checker has found a performance issue in Tensorflow/models/research/sequence_projection/sgnn/sgnn.py: fused_project is repeatedly called in a for loop, but there is a tf.function decorated function func defined and called in fused_project.

In that case, when fused_project is called in a loop, the function func 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

But some variables are depending on the outer function. Code may be more complex if changes are made. Is it necessary to make the change or do you have any other ideas? @nicknochnack