毎度のネタである。最近はCNTKばかりやっていたのだが、TensorFlowにも新しい話題が上がってきた。TensorFlowを使うためのフレームワーク、というかTensorFlowを内包するアプリケーションを開発するためのフレームワークが公開されたようだ。その名をTensorFlow Servingと言う。
Research Blog: Running your models in production with TensorFlow Serving
これを使うと、TensorFlowを利用するためのインタフェースとしてC++を使い、実アプリケーションでTensorFlowを使った機械学習を利用するアプリケーションが開発できるようになる。 確かに、TensorFlowのインタフェースはPythonであり、フロントエンドとしてPythonを使ったアプリケーションを書くことが多かった。 でもちょっと待って欲しい。TensorFlow単体にも、C++のAPIはちゃんと用意されているよ?
https://www.tensorflow.org/versions/r0.7/api_docs/cc/ClassEnv.html#class-tensorflow-env
まあAPIのところをいろいろクリックしても、殆ど「Not Found」になってしまうけれども。 Google先生と言えども、何だか適当だなあ。TensorFlow のC++APIは誰も使っている人がいないのか?それとも開発途中でTensorFlow Servingに切り替えたのだろうか?
TensorFlow Servingの例題を見てみると、例によってMNISTだ。MNISTのコードは以下のようになっている。ヘッダファイル多いな!
いろいろ試してみたいので、例によってTensorFlow Servingの環境をVagrantで自動的に構築できるようにしてみよう。
1. TensorFlow Servingの環境をVagrantで自動的に構築する
予め断わっておきたいのだが、今回もVagrantの仮想環境での実行を想定するため、GPGPU付きでのインストールは行わない。
インストールは、基本的に以下のサイトの指示に従う。念のため、オリジナルのTensorFlowの環境も壊さないように。
remote_file "/home/vagrant/download/bazel-0.1.5-installer-linux-x86_64.sh" do source "https://github.com/bazelbuild/bazel/releases/download/0.1.5/bazel-0.1.5-installer-linux-x86_64.sh" owner 'vagrant' group 'vagrant' mode '0755' action :create end file "/home/vagrant/download/bazel-0.1.5-installer-linux-x86_64.sh" do mode '0755' end execute "install bazel" do cwd "/home/vagrant/download/" command "./bazel-0.1.5-installer-linux-x86_64.sh" end execute "extract python_pip grpcio" do command "pip install grpcio" end git "/home/vagrant/serving" do repository "https://github.com/tensorflow/serving" enable_submodules true user "vagrant" group "vagrant" action :sync end execute "configure tensorflow serving" do cwd "/home/vagrant/serving/tensorflow/" command "./configure" end execute "install tensorflow servivg" do cwd "/home/vagrant/serving/" command "bazel build tensorflow_serving/..." end
TensorFlow Servingのコンパイルとインストールには、およそ1時間かかった。フルスクラッチからコンパイルするのは、相変わらず大変だな。。。