文字列出力モデルのデモ#
概要#
このデモでは、出力精度 ov::element::string
を使用したモデルのデプロイ例を示します。出力テキストは、gRPC proto/REST 本文の対応するフィールドにシリアル化されます。これにより、クライアントはテキストを直接使用し、ラベルマッピングまたはトークン解除のプロセスを回避できます。
TensorFlow から MobileNet モデルをダウンロードして準備#
以下のスクリプトは、公開されている ImageNet データでトレーニングされた MobileNet モデルをダウンロードします。元のモデルは、入力時に 0 ~ 1 の範囲の画像配列を受け取り、トレーニングされたすべてのクラスの確率を返します。入力データの範囲を 0 ~ 255 に変更する前処理関数と、最も可能性の高いラベル名を文字列として取得する後処理関数をモデルに追加しています。これは、モデルレイヤーとして含まれる前処理/後処理機能を使用してモデルをエクスポートできるため、非常に便利な機能です。クライアントは、分類された画像のラベル名を含む文字列データを受信するだけです。
git clone https://github.com/openvinotoolkit/model_server.git
cd model_server/demos/image_classification_with_string_output
pip install -r requirements.txt
python3 download_model.py rm model/1/fingerprint.pb
tree model
model
└── 1
├── assets
├── saved_model.pb
└── variables
├── variables.data-00000-of-00001
└── variables.index
OVMS コンテナの開始#
docker run -d -u $(id -u):$(id -g) -v $(pwd):/workspace -p 8000:8000 openvino/model_server:latest \
--model_path /workspace/model --model_name mobile_net --rest_port 8000
要求を送信#
サンプル・クライアントを使用して、KServ REST API 経由で画像を含む要求を送信します:
python3 image_classification_with_string_output.py --http_port 8000
他の API (KServ GRPC、TFS) を使用して要求を送信することもできます。このセクションでは、さらに短いサンプルコードを見つけることができます:
期待される出力#
Start processing:
Model name: mobile_net
../common/static/images/airliner.jpeg classified as airliner
Iteration 0; Processing time: 31.09 ms; speed 32.16 fps
../common/static/images/arctic-fox.jpeg classified as Arctic fox
Iteration 0; Processing time: 5.27 ms; speed 189.75 fps
../common/static/images/bee.jpeg classified as bee
Iteration 0; Processing time: 3.02 ms; speed 331.46 fps
../common/static/images/golden_retriever.jpeg classified as clumber
Iteration 0; Processing time: 3.12 ms; speed 320.82 fps
../common/static/images/gorilla.jpeg classified as gorilla
Iteration 0; Processing time: 3.04 ms; speed 329.06 fps
../common/static/images/magnetic_compass.jpeg classified as magnetic compass
Iteration 0; Processing time: 3.10 ms; speed 323.00 fps
../common/static/images/peacock.jpeg classified as peacock
Iteration 0; Processing time: 3.24 ms; speed 308.17 fps
../common/static/images/pelican.jpeg classified as pelican
Iteration 0; Processing time: 3.17 ms; speed 315.36 fps
../common/static/images/snail.jpeg classified as snail
Iteration 0; Processing time: 3.06 ms; speed 327.33 fps
../common/static/images/zebra.jpeg classified as zebra
Iteration 0; Processing time: 4.19 ms; speed 238.72 fps