1

Google MediaPipeの'.tflite'を変換した'.mlmodel'を使おうとしています。

しかし、multiArrayの型を変更すると、CoreMLのコンパイルエラーが発生し、解決することができません。

mlmodelの入力タイプは以下のように変更することができました。

# convert_inputType.py :convert multiArray to image type
import coremltools as ct
from coremltools.proto import FeatureTypes_pb2 as ft

spec = ct.utils.load_spec('model_coreml_float32.mlmodel') # miltiArray type
builder = ct.models.neural_network.NeuralNetworkBuilder(spec=spec)

# check input/output features
print('--- Before change:')
builder.inspect_input_features()
builder.inspect_output_features()

# change the input so the model can accept 256x256 RGB images
input = spec.description.input[0]
# del input.type.multiArrayType.shape[0]
input.type.imageType.colorSpace = ft.ImageFeatureType.RGB
input.type.imageType.width = 256
input.type.imageType.height = 256

# converted input/output features
print('--- After change:')
builder.inspect_input_features()
builder.inspect_output_features()

# save inputType-converted model
ct.utils.save_spec(spec, 'selfie_segmentation.mlmodel') # changed type
--- Before change:

[Id: 0] Name: input_1
          Type: multiArrayType {
  shape: 1
  shape: 256
  shape: 256
  shape: 3
  dataType: FLOAT32
}

[Id: 0] Name: activation_10
          Type: multiArrayType {
  dataType: FLOAT32
}

--- After change:

[Id: 0] Name: input_1
          Type: imageType {
  width: 256
  height: 256
  colorSpace: RGB
}

[Id: 0] Name: activation_10
          Type: multiArrayType {
  dataType: FLOAT32
}
  • 'model_coreml_float32.mlmodel' :MediaPipe TFlite から変換済みのmlmodel 入手先:PINTO_model_zoo
  • 'selfie_segmentation.mlmodel' :imageタイプに変更したmlmode, 保存

タイプ変更したmlmodelをXcodeのPeojectに読み込むと、以下のエラーが発生します。

Espresso exception: "Invalid blob shape": generic_elementwise_kernel: cannot broadcast:
----------------------------------------
SchemeBuildError: Failed to build the scheme "testSelfieSegmentation"

compiler error:  Espresso exception: "Invalid blob shape": generic_elementwise_kernel: cannot broadcast:

Compile CoreML model selfie_segmentation.mlmodel:
coremlc: error: compiler error:  Espresso exception: "Invalid blob shape": generic_elementwise_kernel: cannot broadcast:
 (1, 16, 8, 128)
 (1, 16, 2, 128)

モデルの構成を Newtronで確認しましたが, エラーメッセージにある(1,16,8,128)、(1,16,2,128)などのレイヤーは見当たりません。

変更コードに間違いがあるのか、事前にmultiArrayタイプのmlmodelを修正する必要があるのか、もしかすると(1,256,256,3)のshapeは(3,256,256)でなければダメなのか、しかし どう変更したらいいのかわかりません。

何か手がかりになる情報があれば教えてください。

0

この質問に回答するには、ログインする必要があります。

のタグが付いた他の質問を参照する。