如何解决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 举报,一经查实,本站将立刻删除。