Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Keras model evaluate returns triggered tf.function retracing warning
I am training the following model using Keras as shown:
model = tf.keras.models.Sequential([tf.keras.layers.Conv2D(64, (3,3), activation='relu', input_shape=(256, 256, 3)), tf.keras.layers.MaxPooling2D(2, 2), tf.keras.layers.Conv2D(64, (3,3), activation='relu'), tf.keras.layers.MaxPooling2D(2,2), tf.keras.layers.Flatten(), tf.keras.layers.Dense(12, activation=tf.nn.relu), tf.keras.layers.Dense(10, activation=tf.nn.relu), tf.keras.layers.Dense(1, activation=tf.sigmoid)]) model.compile(optimizer = tf.keras.optimizers.Adam(learning_rate=0.0001),loss,'binary_crossentropy, metrics=['accuracy']) model.fit(X_train, y_train, epochs=20)
When running the following to check the accuracy on the test set
I get the following warning:
WARNING:tensorflow:5 out of the last 13 calls to .test_function at 0x000001E51AA92AE8> 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/tutorials/customization/performance#python_or_tensor_args and https://www.tensorflow.org/api_docs/python/tf/function for more details. 2/2 [==============================] - 0s 94ms/step - loss: 0.6660 - accuracy: 0.5909
Can you please help me understand why?