Reputation: 2704
I have a simple Neural Network
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Flatten, Conv2D, MaxPooling2D, MaxPool2D
model = Sequential([
Conv2D(16,(3,3),padding='same', input_shape=(1,28,28),data_format='channels_first'),
MaxPooling2D((3,3), data_format='channels_first')
])
print(model.summary())
summary of model is
Model: "sequential_4"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d_2 (Conv2D) (None, 16, 28, 28) 160
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 16, 9, 9) 0
=================================================================
Total params: 160
Trainable params: 160
Non-trainable params: 0
_________________________________________________________________
None
and compilation as
opt = tf.keras.optimizers.Adam(learning_rate=0.005)
model.compile(optimizer=opt,
loss=tf.keras.losses.BinaryCrossentropy(),
metrics=[tf.keras.metrics.BinaryAccuracy(),
tf.keras.metrics.MeanAbsoluteError()]
)
Now when I print Model attributes, it gives an empty list on metrics. Why is it so?
print(f"{model.metrics}\n{model.optimizer},\n,{model.loss}\n{model.optimizer.lr}")
This is output
[]
<tensorflow.python.keras.optimizer_v2.adam.Adam object at 0x000001FB10F2EDC8>,
,<tensorflow.python.keras.losses.BinaryCrossentropy object at 0x000001FB10F2EEC8>
<tf.Variable 'learning_rate:0' shape=() dtype=float32, numpy=0.005>
Upvotes: 6
Views: 2350
Reputation: 4090
The model will show metrics after training.
So just run model.fit
or model.train_on_batch
and then try again to print. The metrics should appear.
Upvotes: 2
Reputation: 2704
Currently, this is a bug in Tensorflow version 2.2.0. Might be fixed later
Upvotes: 3