【问题标题】:Error converting keras model to coreml ('InputLayer' object is not iterable)将 keras 模型转换为 coreml 时出错(“InputLayer”对象不可迭代)
【发布时间】:2021-03-28 22:46:33
【问题描述】:

我的 keras 模型:

model = Sequential()
model.add(LSTM(128, return_sequences=True, input_shape=(18, 63)))
model.add(LSTM(64))
model.add(Dense(3, activation='softmax'))
model.compile(loss='sparse_categorical_crossentropy',
              optimizer='adam', metrics=['accuracy'])
model.fit(X, Y,  batch_size=30, verbose=2, epochs=90,validation_split=0.2)

我尝试将模型转换为 coreml:

coreml_model = coremltools.converters.keras.convert(
    model,
    input_names=['input'],
    output_names=["output"])

我收到此错误:

TypeError: 'InputLayer' object is not iterable

更新:

coreml_model = coremltools.convert(...)

我得到这个错误(这里是一个不完整的错误代码)

InvalidArgumentError: Attempting to add a duplicate function with name: while_cond_45890 where the previous and current definitions differ. Previous definiton: signature {
  name: "while_cond_45890"
  input_arg {
    name: "while_while_loop_counter"
    type: DT_INT32
  }
  input_arg {
    name: "while_while_maximum_iterations"
    type: DT_INT32
  }
....

【问题讨论】:

  • 这个thread 可能会有所帮助。
  • 不幸的是这没有帮助
  • 我遇到了同样的错误,如果你设法修复它,请告诉我
  • 我决定使用 tflite 模型。它没有任何其他方式工作
  • 那么你是把你的 Keras 模型转换成 tflite 还是重写了整个模型?

标签: keras converters coreml


【解决方案1】:

这个模型是用 tf.keras 还是独立的 Keras 制作的?如果是 tf.keras,你不应该使用 Keras 转换器而是统一转换 API,coremltools.convert(...)

【讨论】:

  • 我试过你的版本,但又出现了一个错误
猜你喜欢
  • 2018-06-27
  • 1970-01-01
  • 2020-01-24
  • 2017-12-10
  • 2018-07-05
  • 2020-10-24
  • 2017-11-12
  • 2018-06-14
  • 1970-01-01
相关资源
最近更新 更多