0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WindowsにおいてYOLO11のモデルをTFLite形式でエクスポートできない問題について

Last updated at Posted at 2025-07-14

遭遇した問題

環境

  • Windows 11
  • Python 3.11
  • VS Code + Jupyter Notebook

Ultralytics YOLOを用いてモデルをTFLite形式に出力しようとしました。

from ultralytics import YOLO

# Load a model
model = YOLO("yolo11n.pt")  # load an official model
#model = YOLO("path/to/best.pt")  # load a custom trained model

# Export the model
model.export(format="tflite")

しかし、以下のようなエラーメッセージが出て出力に失敗しました。どうやらai-edge-litertというライブラリが必要なようです。

Ultralytics 8.3.130  Python-3.11.4 torch-2.1.2+cu118 CPU (Intel Core(TM) i5-9400F 2.90GHz)
YOLO11n summary (fused): 100 layers, 2,616,248 parameters, 0 gradients, 6.5 GFLOPs

PyTorch: starting from 'yolo11n.pt' with input shape (1, 3, 640, 640) BCHW and output shape(s) (1, 84, 8400) (5.4 MB)
requirements: Ultralytics requirements ['ai-edge-litert>=1.2.0', 'protobuf>=5'] not found, attempting AutoUpdate...
WARNING Retry 1/2 failed: Command 'pip install --no-cache-dir "ai-edge-litert>=1.2.0" "protobuf>=5" --extra-index-url https://pypi.ngc.nvidia.com' returned non-zero exit status 1.
WARNING Retry 2/2 failed: Command 'pip install --no-cache-dir "ai-edge-litert>=1.2.0" "protobuf>=5" --extra-index-url https://pypi.ngc.nvidia.com' returned non-zero exit status 1.
WARNING requirements:  Command 'pip install --no-cache-dir "ai-edge-litert>=1.2.0" "protobuf>=5" --extra-index-url https://pypi.ngc.nvidia.com' returned non-zero exit status 1.

TensorFlow SavedModel: starting export with tensorflow 2.12.0...
ERROR TensorFlow SavedModel: export failure 29.9s: cannot import name 'tensor' from 'tensorflow.python.framework' (C:\Users\[username]\AppData\Roaming\Python\Python311\site-packages\tensorflow\python\framework\__init__.py)

そこでpipコマンドでインストールしようとしましたが、

pip install ai-edge-litert

そのようなライブラリは見つからないといわれました。

ERROR: Could not find a version that satisfies the requirement ai-edge-litert (from versions: none)
ERROR: No matching distribution found for ai-edge-litert

原因

PyPIの該当ページを見るとわかりますが、2025年7月現在、ai-edge-litertはmanylinuxmacOS用のファイルしか存在しません。

AIの開発はLinuxで行われることが主流であるために、Windows向けは必ずしも準備されていないのでしょう。

回避策

TFLite以外の形式に出力することも考えました。ただ、Android端末で動かすことが最終目標であり、ネットにあるドキュメントの充実具合を考えるとTFLite形式で出力することがベストのように感じられました。

調べたところ、回避策として、以下の3つがありました。

  1. WSL2を使って、Windows上にLinux仮想環境を用意する
  2. 別のファイル形式を経由する
  3. 別のOSを使う

1. WSL2を使って、Windows上にLinux仮想環境を用意する

Windows Subsystem for Linux 2 (WSL 2)を使うことでLinux仮想環境を実現できます。Windows10以降で64bit版であれば使えます。自分はこの方法を選択しました。

マイクロソフトストア版をインストールするのがおすすめです。

YOLOだけでなくTensorflowも学びたいと思っている方はついでにそちらの環境構築もしておくとよいです。

/mnt/c/でWindowsのCドライブにアクセスすることができます。

仮想環境外で作成したYOLOのチェックポイント(.pt)を仮想環境上でロードしてTFLiteにエクスポートすると失敗することがあります。その時は学習からやり直してチェックポイントを作り直すとうまくいきました。

2. 別のファイル形式を経由する

pytorch -> onnx -> tensorflow(.pbファイル) -> tfliteと迂回する方法です。

3. 別のOSを使う

WindowsではなくMacOSやLinuxに乗り換えるのが、最もシンプルな解決策です。しかし、現実的にこの選択肢を選べる人は少ないでしょう。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?