首页 文章

转换为CoreML时Keras 'InputLayer object has no attribute ' inbound_nodes'

提问于
浏览
3

在尝试将我的Keras模型转换为CoreML模型时,我收到错误'InputLayer object has no attribute'inbound_nodes' .

这是我的代码:

loaded_model = load_model("diffinception.h5")
     coreml_model = coremltools.converters.keras.convert(loaded_model, 
         input_names="imageSculp", output_names="category")
     coreml_model.save("transfertestinception.mlmodel")

“diffinception.h5”是从Keras导入的Inception模型,其中包含我为转移学习而训练的其他图层 .

这是我生成该模型的代码:

model = applications.InceptionV3(weights = "imagenet", include_top=False,         
    input_shape = (img_width, img_height, 3), pooling = max)

    # Freeze layers
    for layer in model.layers:
        layer.trainable = False

    #Adding custom Layers
    x = model.output
    x = Flatten()(x)
    x = Dense(1024, activation="relu")(x)
    x = Dropout(0.5)(x)
    x = Dense(1024, activation="relu")(x)
    predictions = Dense(2, activation="softmax")(x)

    # creating the final model
    model_final = Model(inputs = model.input, outputs = predictions)
    # compile the model
    model_final.compile(loss = "categorical_crossentropy", optimizer =                                         
        optimizers.SGD(lr=0.001, momentum=0.9), metrics=["accuracy"])

我与Keras的版本保持同步 . 使用Python 2.7

1 回答

相关问题