【问题标题】:coremlc: Error: compiler error: generic_reshape_kernel: Invalid bottom shape (64 8 -2 1 1) for reshape to (4096 -1 1 1 1)coremlc:错误:编译器错误:generic_reshape_kernel:无效的底部形状(64 8 -2 1 1)重塑为(4096 -1 1 1 1)
【发布时间】:2020-07-19 02:15:06
【问题描述】:

我已将我的 CNN keras 模型转换为 .mlmodel 以部署在 CoreML 移动应用程序上,但我收到以下错误消息:

coremlc: Error: compiler error: Espresso exception: "Invalid 
argument":generic_reshape_kernel: Invalid bottom shape (64 8 -2 1 1) for 
reshape to (4096 -1 1 1 1)Command CoreMLModelCompile failed with a nonzero 
exit code

这是我在运行应用程序时收到的唯一错误消息。 这个错误的根源是什么,我该如何解决?

任何帮助将不胜感激,谢谢。

这是 .mlmodel 的详细信息: mlmodel details

【问题讨论】:

  • 可能是输入尺寸太小了?底部形状的-2非常可疑。请在您的问题中包含实际的 Keras 模型定义;没有这个,就无法诊断问题。
  • 感谢您的回复,我会把模型发给您。
  • 你修好了吗?我有同样的问题@ABH
  • 是的,问题出在我的 keras 模型和转换代码中。首先,keras 模型是使用 keras 和 Tensorflow 库编写的,这在我的情况下是不必要的并导致了上述问题,因此我将代码切换为仅在 keras 模块/函数上运行。其次,在我的 CoreML 转换代码中,我使用 Tensorflow 加载了我的 keras 模型,该模型由于不兼容而最终丢失了尺寸。因此,解决方案是在创建和转换中坚持一个模型,在我的例子中是 keras 模型。
  • 谢谢您的回答,我会尽力让您知道这是否有效!我也混合了 keras nad tf 语句,所以这可能是问题所在!

标签: ios swift coreml conv-neural-network coremltools


【解决方案1】:

这就是我解决问题并创建 CNN keras 模型然后将其转换为 MLModel 的方法

1- 导入 keras 并使用 keras 独立模块/功能/等。

例如,而不是这个..

import tensorflow as tf
from tensorflow.keras import datasets, layers, models
from tensorflow.keras.preprocessing.image import ImageDataGenerator

这样做..

import keras
from keras import datasets, layers, models
from keras.preprocessing.image import ImageDataGenerator

2- 保持一致并选择 keras 转换器以匹配您已经创建的 keras 模型

例如..

import coremltools

output_labels = []
model = coremltools.converters.keras.convert('cnn_keras_model.h5',
                                             input_names=['images'],
                                             output_names=['output'],
                                             class_labels=output_labels,
                                             image_input_names='image')

model.save('converted_cnn_keras_model.mlmodel')

【讨论】:

    猜你喜欢
    • 2020-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-01
    • 1970-01-01
    相关资源
    最近更新 更多