簡體   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