Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

tensorflow2.0 - Tensorflow 2.0: tf.feature_columns are triggering tf.function retracing warning

I'm using tensorflow 2.4.0 to train a dnn but I've been getting the following waring after saving and then loading the model:

WARNING:tensorflow:11 out of the last 11 calls to <function recreate_function.<locals>.restored_function_body at 0x7f14b49933b0> triggered tf.function retracing. 
Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. 
For (1), please define your @tf.function outside of the loop. 
For (2), @tf.function has experimental_relax_shapes=True option that relaxes argument shapes that can avoid unnecessary retracing. 
For (3), please refer to https://www.tensorflow.org/guide/function#controlling_retracing and https://www.tensorflow.org/api_docs/python/tf/function for more details.

The surprising thing is that I don't have any custom functions in my code. After debugging by including only one input at a time, I found that these few lines are triggering the warning.

categorical_column = tf.feature_column.categorical_column_with_vocabulary_list(col_name, ['A', 'B', 'C', 'D'])
feature_columns[col_name] = tf.feature_column.indicator_column(categorical_column=categorical_column)

But there is no way to add the @tf.function decorator to this code, since these are not custom functions but tf.feature_columns.

Is this the expected behaviour? Is there a way to remove the warnings?

question from:https://stackoverflow.com/questions/66064840/tensorflow-2-0-tf-feature-columns-are-triggering-tf-function-retracing-warning

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...