tensorflow serving模型转换

    tf serving是一款灵活的高性能机器学习服务系统,专为生产环境而设计。通过它可以轻松部署新算法和实验,同时保持服务框架和API不变。它提供了与tensorflow模型的即是可用集成,但很容易扩展以便服务其他类型的模型和数据。

    tf serving的安装过程详见官网介绍。

    此处主要介绍tensorflow模型在docker中转换时的修改内容。

  1. 修改inception_saved_model.py文件中的内容,主要包括:image_size,NUM_CLASSES,SYNSET_FILE,METADATA_FILE变量的内容,必要时修改model_version,NUM_TOP_CLASSES。
  2. 修改inception_model.py文件中的内容,包括从nets文件夹中导入所需网络的信息,修改inference函数中对应的网络名称。
from nets.inception_v1 import inception_v1, inception_v1_arg_scope

with slim.arg_scope(inception_v1_arg_scope()):
    logits, endpoints = inception_v1(
          images,
          dropout_keep_prob=0.8,
          num_classes=num_classes,
          is_training=for_training,
          scope=scope)

另,使用CUDA环境时,需要添加环境及bazel编译的配置项

export TF_NEED_CUDA=1
bazel build -c opt --config=cuda tf_models/slim:inception_saved_model

ps,关于gpu的设置如下:

export CUDA_VISIBLE_DEVICES='0,1'   #shell环境

import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0,1"  #python环境

 

你可能感兴趣的:(开发周边)