簡體   English   中英

CoreML中Python Tensorflow模型的圖像輸入

[英]Image input for Python Tensorflow model in CoreML

我正在使用張量流(python)實現一個簡單的圖像分類模型。

這是我的圖像預處理:

import glob
for filename in glob.glob('/Volumes/G-DRIVE mobile USB-C/traan/*.jpeg'): #assuming jpeg
    im=Image.open(filename)
    im = im.resize((150,120), Image.ANTIALIAS)
    print(im.size)
    training_images.append(im)

這是我非常簡單的模型:

model = keras.Sequential([
    keras.layers.Flatten(input_shape=(120, 150, 3)),
    keras.layers.Dense(512, activation=tf.nn.relu),
    keras.layers.Dense(256, activation=tf.nn.relu),
    keras.layers.Dense(128, activation=tf.nn.relu),
    keras.layers.Dense(10, activation=tf.nn.softmax)
])

我想將此模型加載到CoreML中,

import coremltools

modelCoreML = coremltools.converters.tensorflow.convert(model, input_feature, output_feature)
modelCoreML.save("Model.mlmodel")

但是如何在可以輸入圖像而不是numpy堆棧的位置執行此操作? 我應該在應用程序本身中處理圖像並將其轉換為正確的格式,然后將其放入模型中嗎? 我該怎么做?

您需要向coremltools.converters.keras.convert()提供image_input_names參數,以便coremltools知道應將哪些輸入視為圖像。 文檔中對此進行了說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM