属性错误:模块"keras.layers.normalization"没有属性"批处理规范化"



我正在尝试将一个迁移学习Keras模型转换为Core ml。我需要这个Core ml文件具有class_labels,以便将该模型识别为分类器。每当我尝试调用ct.converters.keras.convert()时,都会收到错误的AttributeError:模块"keras.layers.normalization"没有属性"BatchNormalization"。

我想知道如何添加class_labels,以及如何用我的模型调用这个函数。或者只是用Dictionary(String→Double(输出。如有任何帮助,我们将不胜感激。

下面是我的模型训练代码(谷歌colab(

base_model = InceptionV3(
include_top=False,
weights='imagenet',
input_shape=(224,224,3))

base_model.trainable=False

model = tf.keras.Sequential([ 
base_model,
tf.keras.layers.Dropout(0.1),
tf.keras.layers.GlobalAveragePooling2D(),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(12, activation='softmax')
])
model.compile(optimizer='Adam',loss='categorical_crossentropy',metrics=['accuracy'])
early = tf.keras.callbacks.EarlyStopping( patience=10,
min_delta=0.001,
restore_best_weights=True)
checkpoint = tf.keras.callbacks.ModelCheckpoint("/content/drive/My Drive/Colab_Notebooks/Models/plant_classifier_10.h5",monitor='val_accuracy', verbose=1, save_best_only=True, save_weights_only=False, mode='auto', save_freq='epoch')
batch_size=32
STEP_SIZE_TRAIN = training_set.n//training_set.batch_size
STEP_SIZE_VALID = test_set.n//test_set.batch_size

history = model.fit(training_set,
steps_per_epoch=STEP_SIZE_TRAIN,
validation_data=test_set,
validation_steps=STEP_SIZE_VALID,
epochs=10,
callbacks=[early, checkpoint])

下面是我尝试的转换代码(谷歌colab(

model = keras.models.load_model('/content/drive/MyDrive/Colab_Notebooks/Models/plant_classifier.h5')
core_modelB = ct.converters.keras.convert(model, 
input_names="image",
image_input_names="image",
class_labels=['Black-grass', 'Charlock', 'Cleavers', 'Common Chickweed', 'Common wheat', 'Fat Hen', 'Loose Silky-bent', 'Maize', 'Scentless Mayweed', 'Shepherd’s Purse', 'Small-flowered Cranesbill', 'Sugar beet'],
output_names=("labelProbability"))
core_model.save('Plant_Classifier_New.mlmodel')

我得到错误AttributeError:模块'keras.layers.normalization'在最后一行的ct.converters.keras.convert()函数末尾没有属性'BatchNormalization'

这是错误消息的图片。https://i.stack.imgur.com/CFtFR.png

任何帮助都将是惊人的。

尝试ct.converters.convert(…(,因为ct.convesters.keras.convert((用于旧的keras版本,该版本是围绕TensorFlow 1.x包装的。

最新更新