CoreML 转换无法识别 ImageType

问题描述

我有一个简单的分类器,我正在尝试将其转换为 CoreML,但是,尽管此代码上周可以正常工作,但我无法使转换正常工作。我想将输入指定为图像,但无论我进行什么更改,它总是显示MultiArray,这意味着我无法使用 Vision 运行模型。

这是最小的代码

import tensorflow as tf #v2.3.1
import coremltools #v4.1

with open("env_labels.txt") as f:
    targets = [l.strip() for l in f.readlines()] #Flat list of labels

new_model = tf.keras.applications.MobileNetV2(
                    input_tensor = tf.keras.layers.Input(shape=[224,224,3],name="image_input"),alpha = 0.35,include_top=False
                                 )

x = tf.keras.layers.GlobalMaxPooling2D()(new_model.output)
x = tf.keras.layers.Dropout(0.2)(x)
x = tf.keras.layers.Dense(len(targets),activation="softmax",dtype=tf.float32,name="dense_{}".format(len(targets)))(x)

new_model = tf.keras.models.Model(new_model.input,x)

print(new_model.input.name) # Gives 'image_input:0'

#I have tried this with and without the call to split,but get the same results
image_input = coremltools.ImageType(name=new_model.input.name.split(":")[0],shape=(1,3),scale=2 / 255.0,bias=[-1.0,-1.0,-1.0])

classifier_config = coremltools.ClassifierConfig(targets)

mlmodel = coremltools.convert(
        new_model,inputs=[image_input],classifier_config=classifier_config
    )

print(mlmodel.input_description) #Gives Features(image_input)

如果有人有任何见解,请告诉我。我怀疑它可能与 : 相关,但到目前为止,更改并没有帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)