是否可以将coreml模型中输入张量的类型从多数组更改为图像?

时间:2019-09-24 11:02:30

标签: image tensorflow coreml

我有一个带有这些参数的coreml模型,我想将输入张量的类型从形状为(112,112,3)的Multiarray更改为RGB图像(112,112)

Core ML input(s):
[name: "input_to_float__0"
type {
multiArrayType {
shape: 3
shape: 112
shape: 112
dataType: DOUBLE
}
}
]
Core ML output(s):
[name: "logits__BiasAdd__0"
type {
multiArrayType {
shape: 80
dataType: DOUBLE
} 
}
]

enter image description here

有可能这样做吗?

我该怎么做?

1 个答案:

答案 0 :(得分:1)

在将模型转换为Core ML(使用image_input_names)时,最简单的方法是指定此名称。

但是您也可以使用一些Python来解决此问题:

import coremltools
import coremltools.proto.FeatureTypes_pb2 as ft
spec = coremltools.utils.load_spec("YourModel.mlmodel")
input = spec.description.input[0]
input.type.imageType.colorSpace = ft.ImageFeatureType.RGB
input.type.imageType.height = 112
input.type.imageType.width = 112
coremltools.utils.save_spec(spec, "YourNewModel.mlmodel")