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?

More than 1 year has passed since last update.

scikit-learnやlightgbmなどのONNX形式モデルがブラウザで動作しないとき

Last updated at Posted at 2022-01-11

やりたいこと

Pythonで訓練したモデルをONNX形式でブラウザ上(JavaScript)で推論させたい。

使用ライブラリ

  • Python
    • scikit-learn/lightgbm
    • onnxmltools
  • JavaScript
    • onnxruntime-web

問題

JSのサンプルコード通りに書いてもsession.run()部分で4123988のようなエラーが出て動かない。

解決法

PythonでモデルをONNX形式に変換する際、zipmapオプションを無効にしないとブラウザでは動かないらしい。
例えば、LightGBMモデルだとこんな感じ。

import onnxmltools
onnx_model = onnxmltools.convert_lightgbm(model, initial_types=initial_types, zipmap=False)

参考

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?