1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

TensorFlow Lite 実行環境を作る win/linux

Last updated at Posted at 2022-11-11

実行するだけなら本来ランタイムだけでいいのですが、windowsではTensorFlowLiteのruntimeはサポートされていないので、tenosrflowパッケージを丸々インストールします。

従って、同じ実行コードを使うなら、linux/winでimport文が変わります。
こんな風に書けばよしです。

try:
    # linux
    import tflite_runtime.interpreter as tflite
except ImportError:
    # win
    from tensorflow import lite as tflite

バージョンによって問題が置きがち(特にnumpy, 組み込み向けのとき, 開発と実行環境が別のとき)なのでバージョン指定します。
tensorflowtflite-runtimeは同じバージョンNo.でよしです。

最終的にはRequirements Fileをちゃんと書いてあげたいところです。

ほとんどの場合PILとnumpyが必要なので書いてあります。
他の必要なモジュールは追加してください。

windowsでpipで

py.exe -m pip install numpy==1.19.3
py.exe -m pip install pillow==9.0.1
py.exe -m pip install tensorflow==2.10.0

linuxでpipで

python -m pip install numpy==1.19.3
python -m pip install pillow==9.0.1
python -m pip install tflite-runtime==2.10.0

pyenvするなら

それぞれ次のコマンド

始めるとき

venv DIRNAME
.\DIRNAME\Scripts\activate

抜け出すとき

deactivete

pipがないとき

https://pip.pypa.io/en/stable/installation/#get-pip-pyに従って

get-pip.pyをダウンロードして、これを

  • win: py get-pip.py
  • linux: python get-pip.py
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?