
変換済みCoreMLModel(GitHub)
###TensorFlow Hubのモデルコレクションからダウンロードしてモデルを構築。
m = tf.keras.Sequential([
hub.KerasLayer("https://tfhub.dev/tensorflow/efficientnet/b0/classification/1")
])
m.build([1, 224, 224, 3])
m.summary()
###クラスラベルを読み込んでおきます。
(今回はImageNetの1000クラスでそのまま使用。TensorFlowHubには転移学習のできるバージョンも公開されています。)
import urllib
label_url = 'https://storage.googleapis.com/download.tensorflow.org/data/ImageNetLabels.txt'
class_labels = urllib.request.urlopen(label_url).read().splitlines()
class_labels = class_labels[1:] # remove the first class which is background
assert len(class_labels) == 1000
# make sure entries of class_labels are strings
for i, label in enumerate(class_labels):
if isinstance(label, bytes):
class_labels[i] = label.decode("utf8")
###CoreMLTools4.0で変換します。
import coremltools as ct
image_input = ct.ImageType(shape=(1, 224, 224, 3,),
scale=1/255)
mlmodel = ct.convert(m,
inputs=[image_input],
classifier_config=classifier_config,
)
mlmodel.save('./efficientnet.mlmodel')

Core MLを使ったアプリを作っています。
機械学習関連の情報を発信しています。
Twitter
[MLBoysチャンネル]
(https://www.youtube.com/channel/UCbHff-wfjTnB3rtXIP6y0xg)
Medium