Vengineerの妄想(準備期間)

人生は短いけど、長いです。人生を楽しみましょう!

IntelがTensorFlow学習済みモデルをC++モデルに変換


Twitterにツイートしたら、なかなか人気だったので。。記録として。


引用します。
 Light Model Transformer is a light tool that could transform trained tensorflow model into C++ code. 
 The generated code is based on Intel MKLDNN and provides interface to do inference without any framework, 
 intent to accelerate the inference performance.

C++に変換したモデルは、IntelのMKL-DNN を使ったモデルになると。

まずは、MKL-DNN をインストール

  $ python install_mkldnn.py

次に、次の2つのツールでTensorFlowの学習済みモデルを変換するだけ
最初は、TensorFlowモデルを中間表現(topo)にし、その後、中間表現からコードに変換。
  $ python tf2topo.py --input_model_filename=./frozen.pb \
              --weights_file=saved_model/weights.bin \
              --pkl_file=saved_model/weights.pkl \
              --topo_file=saved_model/topo.txt

  $ python topo2code.py --topo=saved_model/topo.txt

これでできるのなら、TensorFlow XLA の AOT より簡単じゃん。

Intel MKL-DNN を使うので多分、XLA AOT より速いと思う。

Intel って、x86 のを使えるのなら、なんでもするって感じですね。