Tensorflow Keras 指标未显示

Ahm*_*nis 6 python keras tensorflow

我有一个简单的神经网络

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())
Run Code Online (Sandbox Code Playgroud)

模型的总结是

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
Run Code Online (Sandbox Code Playgroud)

和编译为

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
Run Code Online (Sandbox Code Playgroud)

现在,当我打印模型属性时,它会给出一个空的指标列表。为什么会这样呢?

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()]
              )
Run Code Online (Sandbox Code Playgroud)

这是输出

[]
<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>
Run Code Online (Sandbox Code Playgroud)

Ahm*_*nis 3

目前,是 Tensorflow 2.2.0 版本中的一个错误。稍后可能会修复