繁体   English   中英

转换为CoreML时,Keras的InputLayer对象没有属性“inbound_nodes”

[英]Keras 'InputLayer object has no attribute 'inbound_nodes' when converting to CoreML

在尝试将我的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

我在我的机器上更新了_topology2.py代码以匹配下面的版本(2018年1月17日更新):

https://github.com/apple/coremltools/blob/master/coremltools/converters/keras/_topology2.py

这解决了这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM