TensorFlow 模型建立与训练

@ifwant 经过调试发现是预训练模型本身的问题,可参考 https://zhuanlan.zhihu.com/p/64310188 。解决方案是为预训练模型的部分层手动开启训练模式,即加入

tf.keras.backend.set_learning_phase (True)

或者在调用模型的时候加入 training=True 参数,即

labels_pred = model (images, training=True)

我在写这段示例代码的时候没遇到这样的问题,可能是年代久远了。

@LiuPineapple 可能是环境配置的问题,请换个电脑或者在云端运行试试看。