I wrote a layer, which does nothing
class Fractal2D(tf.keras.layers.Layer):
def __init__(self, kernel_size_range):
super(Fractal2D, self).__init__()
self.kernel_size_range = kernel_size_range
def build(self, inputs):
print(f'build executes eagerly: {tf.executing_eagerly()}')
return inputs
def call(self, inputs):
print(f'call executes eagerly: {tf.executing_eagerly()}')
return inputs
and made a model
model = tf.keras.Sequential([
tf.keras.layers.InputLayer(input_shape=(224, 224, 3), batch_size=32),
Fractal2D(kernel_size_range=(3, 41)),
hub.KerasLayer("https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/4", output_shape=[1280],
trainable=False),
tf.keras.layers.Dense(DIAGNOSIS_NUMBER, activation='softmax')
])
the output from the cell is
build executes eagerly: True
call executes eagerly: False
When I train the model
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
model.fit(training_set, validation_data=validation_set, epochs=20)
I get
Epoch 1/20
call executes eagerly: False
call executes eagerly: False
Questions:
- Why build and call method are executed, when the model is instantiated?
- Why call method is NOT executed eagerly, if the eager execution is the default method of execution?