画像分類のデモ (C++)#

このデモは 2 つのクライアントを提供します:

  • classification_client_sync - 同期 gRPC API を使用したシンプルなクライアントであり、分類モデルの精度をテストします

  • classification_client_async_benchmark - 非同期 gRPC API を使用するクライアントであり、実際の画像データを使用して精度とパフォーマンスをテストします

クライアントをビルドするには、このディレクトリーで make コマンドを実行します。すべての依存関係を含む ovms_cpp_image_classification という名前の Docker イメージが作成されます。クライアント・イメージの例には、精度測定に必要なテストイメージも含まれています。カスタムイメージを使用することもできます。

git clone https://github.com/openvinotoolkit/model_server.git 
cd model_server/demos/image_classification/cpp make

: このディレクトリーには、ベンチマーク・クライアントに固有のコードのみが表示されます。他の C++ デモと共有されるコードやすべてのビルド・ユーティリティーは、共通の C++ ディレクトリーに配置されます。

分類モデルの準備#

resnet50-binary モデルで OVMS を開始します:

curl -L --create-dir https://storage.openvinotoolkit.org/repositories/open_model_zoo/2022.1/models_bin/2/resnet50-binary-0001/FP32-INT1/resnet50-binary-0001.bin -o resnet50-binary/1/model.bin https://storage.openvinotoolkit.org/repositories/open_model_zoo/2022.1/models_bin/2/resnet50-binary-0001/FP32-INT1/resnet50-binary-0001.xml -o resnet50-binary/1/model.xml

同期的に予測を要求するクライアント#

クライアントは要求を同期的に送信し、各要求の待ち時間を表示します。反復数とレイアウト (nchwnhwc、または binary) を指定できます。各要求には、選択した形式の画像が含まれます。クライアントはサーバーの応答の正確性もテストします。

サーバーの準備#

docker run -d -u $(id -u):$(id -g) -v $(pwd)/resnet50-binary:/model -p 9001:9001 openvino/model_server:latest \ 
--model_path /model --model_name resnet --port 9001 --layout NHWC:NCHW

クライアントの開始#

docker run --rm --network host -e "no_proxy=localhost" -v 
${PWD}/input_images.txt:/clients/input_images.txt ovms_cpp_image_classification ./classification_client_sync --grpc_port=9001 --iterations=10 --layout="binary" 

Address: localhost 
Images list path: input_images.txt 
Layout: binary 
call predict ok 
call predict time: 6ms 
outputs size is 1 
call predict ok 
call predict time: 5ms 
outputs size is 1 
call predict ok 
call predict time: 4ms 
outputs size is 1 
call predict ok 
call predict time: 4ms 
outputs size is 1 
call predict ok 
call predict time: 4ms 
outputs size is 1 
call predict ok 
call predict time: 4ms 
outputs size is 1 
call predict ok 
call predict time: 5ms 
outputs size is 1 
call predict ok 
call predict time: 4ms 
outputs size is 1 
call predict ok 
call predict time: 4ms 
outputs size is 1 
call predict ok 
call predict time: 5ms 
outputs size is 1 
Overall accuracy: 100% 
Total time divided by number of requests: 5ms

非同期的に予測を要求するクライアント#

クライアントは、並列クライアントのシナリオを模倣するために要求を非同期に送信します。これらのクライアントを構成するパラメーターは多数あります。

名前

説明

デフォルト

合成データで利用可能

grpc_address

grpc サービスへの URL

localhost

はい

grpc_port

grpc サービスへのポート

9000

はい

model_name

要求するモデル名

resnet

はい

input_name

画像付きのテンソル名を入力

0

いいえ (自動的に推測)

output_name

分類結果を含む出力テンソル名

1463

いいえ

イテレーター

各プロデューサー・スレッドによって送信される要求数

10

はい

batch_size

箔反復のバッチサイズ

1

いいえ (自動的に推測)

images_list

ラベル付き画像のリストを含むファイルへのパス

input_images.txt

いいえ

layout

binary、nhwc または nchw

nchw

いいえ (自動的に推測)

プロデューサー

予測を非同期にスケジュールするスレッド数

1

はい

コンシューマー

応答を受信するスレッドの数

8

はい

max_parallel_requests

並列推論要求の最大数。0=制限なし

100

はい

benchmark_mode

1 - 前/後処理とログを削除。0 - 精度測定を有効化

0

いいえ

実際の画像データを使用する非同期クライアント#

サーバーの準備#

docker run -d -u $(id -u):$(id -g) -v $(pwd)/resnet50-binary:/model -p 9001:9001 openvino/model_server:latest \ 
--model_path /model --model_name resnet --port 9001 --layout NCHW

クライアントの開始#

docker run --rm --network host -e "no_proxy=localhost" -v 
${PWD}/input_images.txt:/clients/input_images.txt ovms_cpp_image_classification ./classification_client_async_benchmark --grpc_port=9001 --layout="nchw" --iterations=2000 --batch_size=1 
--max_parallel_requests=100 --consumers=8 --producers=1 --benchmark_mode=1 

Address: localhost:9001 
Model name: resnet 
Images list path: input_images.txt 

Running the workload...
======================== 
        Summary 
======================== 
Benchmark mode: True 
Accuracy: N/A 
Total time: 1976ms 
Total iterations: 2000 
Layout: nchw 
Batch size: 1 
Producer threads: 1 
Consumer threads: 8 
Max parallel requests: 100 
Avg FPS: 1012.15