import keras
from keras.layers.normalization import BatchNormalization
import tensorflow as tf
x = tf.keras.layers.Conv2D(16, kernal, activation='relu', padding='same')(x)
x = BatchNormalization()(x)
这是因为我既用了Keras里面的BatchNormalization, 又用了tf.keras里面的layer,导致冲突。把他们全部改为从tf.keras的layer或者Keras中的layer就好了,如下代码。
import tensorflow as tf
x = tf.keras.layers.Conv2D(16, kernal, activation='relu', padding='same')(x)
x = tf.keras.layers.BatchNormalization()(x)