【问题标题】:Keras 'InputLayer object has no attribute 'inbound_nodes' when converting to CoreMLKeras 'InputLayer 对象在转换为 CoreML 时没有属性'inbound_nodes'
【发布时间】:2018-06-27 23:44:33
【问题描述】:

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

【问题讨论】:

  • 您使用的 Keras 版本比 coremtools 支持的版本更新。

标签: python tensorflow keras coreml coremltools


【解决方案1】:

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

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

这解决了问题。

【讨论】:

    猜你喜欢
    • 2018-07-07
    • 2021-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-23
    • 2019-03-23
    • 2017-12-10
    • 2017-09-10
    相关资源
    最近更新 更多