coreml(apple)を試してみました

以下の記事を参考にcoreml(apple)を試してみました。

coremltools 3.1の環境構築(2019年11月版) - Qiita

実行環境

環境構築

appleのcoremltoolsを参考に環境構築。

apple/coremltools: Core ML Community Tools.

# 仮想環境作成
$ pip install virtualenv
$ virtualenv coreml
$ coreml/bin/activate

# coreml
(coreml) $ pip install -U coremltools
(coreml) $ pip install keras==2.2.4 tensorflow==1.14.0

# jupyter-labで実行するカーネルをインストール
(coreml) $ pip install ipykernel
(coreml) $ ipython kernel install --user --name=coreml

# jupyter-labインストール
(coreml) $ pip install jupyterlab

カーネルインストールは以下を参考にしました。

実行

jupyter-labを起動します。仮想環境外でもjupyter-labをインストールしている可能性があるので仮想環境のjupyter-labをパスを指定して呼び出した方が確実です。

$ coreml/bin/jupyter-lab

f:id:unokun3:20191124045735p:plain

インストールしたカーネルを選択します。

「Kernel/change kernel]メニューをクリック。

インストールしたカーネルの名前を選択します。

f:id:unokun3:20191124045931p:plain

画面右上のカーネルが選択したカーネル名になっていることがわかります。 f:id:unokun3:20191124050128p:plain

このままだとインストールしたモジュールが使えないのでパスを設定します。

設定前 f:id:unokun3:20191124050254p:plain

設定後 f:id:unokun3:20191124050318p:plain

インストールしたモジュール(Keras、tensorfow)のバージョンを確認します。 f:id:unokun3:20191124050602p:plain f:id:unokun3:20191124050627p:plain

updatable_mnist.ipynbを選択して実行します。問題なく最後まで実行できます。 f:id:unokun3:20191124050841p:plain

tensorflowをバージョン指定しない(2.0)場合、OperatorNotAllowedInGraphErrorが発生します。 f:id:unokun3:20191124051109p:plain f:id:unokun3:20191124051123p:plain

TODO

作成したモデルをアプリに組み込む予定です。