以安装用户HwHiAiUser为例,介绍启动TF Serving的操作方法,实际操作时请根据实际路径进行替换。本文中举例路径均需要确保安装用户具有读或读写权限。
platform_configs { key: "tensorflow" value { source_adapter_config { [type.googleapis.com/tensorflow.serving.SavedModelBundleSourceAdapterConfig] { legacy_config { session_config { graph_options { rewrite_options { custom_optimizers { name: "NpuOptimizer" parameter_map: { key: "use_off_line" value: { b: true } } parameter_map: { key: "mix_compile_mode" value: { b: true } } parameter_map: { key: "graph_run_mode" value: { i: 0 } } parameter_map: { key: "precision_mode" value: { s: "force_fp16" } } } remapping: OFF } } } } } } } }
model_config_list:{ config:{ name:"inception_v3_flowers", # 模型名称 base_path:"/home/HwHiAiUser/tf_serving_test/inception_v3_flowers", # 模型所在路径 model_platform:"tensorflow" }, config:{ name:"inception_v4", base_path:"/home/HwHiAiUser/tf_serving_test/inception_v4", model_platform:"tensorflow" }, config:{ name:"inception_v4_imagenet", base_path:"/home/HwHiAiUser/tf_serving_test/inception_v4_imagenet", model_platform:"tensorflow" } }
squeezenext/ └── 1 ├── saved_model.pb └── variables ├── variables.data-00000-of-00001 └── variables.index
1为版本号,请参见以上目录结构存放。
export LD_LIBRARY_PATH=/home/HwHiAiUser/Ascend/tfplugin/latest/python/site-packages/npu_bridge:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/HwHiAiUser/xxx/serving-1.15.0/third_party/tf_adapter:$LD_LIBRARY_PATH
“xxx”为TF Serving的安装路径。
. /home/HwHiAiUser/Ascend/ascend-toolkit/set_env.sh
. /home/HwHiAiUser/Ascend/nnae/set_env.sh
. /home/HwHiAiUser/Ascend/tfplugin/set_env.sh
export PATH=/usr/local/python3.7.5/bin:$PATH export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib:$LD_LIBRARY_PATH
tensorflow_model_server --port=8500 --rest_api_port=8501 --model_base_path=/home/HwHiAiUser/tf_serving_test/squeezenext --model_name=squeezenext --platform_config_file=/home/HwHiAiUser/tf_serving_test/config.cfg
多个模型时执行如下命令:
tensorflow_model_server --port=8500 --rest_api_port=8501 --model_config_file=/home/HwHiAiUser/tf_serving_test/models.config --allow_version_labels_for_unavailable_models=true --model_config_file_poll_wait_seconds=60 --platform_config_file=/home/HwHiAiUser/tf_serving_test/config.cfg
此处需要使用绝对路径。启动成功如下图所示:
通过tensorflow_model_server --help命令可查看启动方式及参数,参数解释如下表所示。
参数 |
说明 |
示例 |
---|---|---|
--port |
使用GPRC方式进行通信。 |
8500 |
--rest_api_port |
使用HTTP/REST API方式进行通信,如果设置为0则不生效,且指定的端口号必须与GPRC不同。 |
8501 |
--model_config_file |
加载多个模型时,则需要配置此参数文件以导入多个模型,且与模型和--platform_config_file参数配置文件在同一目录下。 |
/home/HwHiAiUser/tf_serving_test/models.config |
--model_config_file_poll_wait_seconds |
此参数设置对--model_config_file配置文件刷新时间间隔。当服务开启时,将实时刷新写入--model_config_file配置文件的模型并加载到服务端中。 单位“s”。 |
60 |
--model_name |
加载一个模型时使用该参数,其值为模型所在版本目录的父目录名。 |
squeezenext |
--model_base_path |
加载的模型所在路径,若已配置--model_config_file则可忽略。 |
/home/HwHiAiUser/tf_serving_test/squeezenext |
--platform_config_file |
特性配置文件。 |
/home/HwHiAiUser/tf_serving_test/config.cfg |