在modelarts上部署backend为TensorFlow的keras模型
2019-09-24 11:19
801 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/devcloud/article/details/101272608
最近老山在研究在modelarts上部署mask-rcnn,源代码提供的是keras模型。我们可以将keras转化成savedModel模型,在TensorFlow Serving上部署,可参考老山的上篇部署文章。至于输入和输出张量,到已经预先存在model.input和model.output中了。
不多说,直接上代码。
[code]from keras import backend as K import tensorflow as tf # 在此之前,先加载keras模型 # 。。。 # 加载完成 with K.get_session() as sess: export_path = './saved_model' builder = tf.saved_model.builder.SavedModelBuilder(export_path) signature_inputs = { 'input_image': tf.saved_model.utils.build_tensor_info(model.input[0]), 'input_image_meta': tf.saved_model.utils.build_tensor_info(model.input[1]), 'input_anchors': tf.saved_model.utils.build_tensor_info(model.input[2]), } signature_outputs = { 'mrcnn_detection':tf.saved_model.utils.build_tensor_info(model.output[0]), 'mrcnn_class':tf.saved_model.utils.build_tensor_info(model.output[1]), 'mrcnn_bbox':tf.saved_model.utils.build_tensor_info(model.output[2]), 'mrcnn_mask':tf.saved_model.utils.build_tensor_info(model.output[3]), 'ROI':tf.saved_model.utils.build_tensor_info(model.output[4]), 'rpn_class':tf.saved_model.utils.build_tensor_info(model.output[5]), 'rpn_bbox':tf.saved_model.utils.build_tensor_info(model.output[6]), } classification_signature_def = tf.saved_model.signature_def_utils.build_signature_def( inputs=signature_inputs, outputs=signature_outputs, method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME) builder.add_meta_graph_and_variables( sess, [tf.saved_model.tag_constants.SERVING], signature_def_map={ 'root': classification_signature_def }, ) builder.save()
作者:山找海味
相关文章推荐
- Keras学习3:模型Model
- [keras] 模型可视化plot_model
- 用keras训练模型并用Tensorflow的C++API调用模型
- keras的backend 设置 tensorflow,theano
- java加载tensorflow训练好的模型部署成service
- tensorflow模型java部署问碰到了坑,各种坑
- keras框架 反复调用model 模型 出错
- tensorflow入门8 模型部署1
- keras系列︱Sequential与Model模型、keras基本结构功能(一)
- keras(tensorflow后端)给模型建立单独的graph
- 基于循环神经网络实现基于字符的语言模型(char-level RNN Language Model)-tensorflow实现
- MLSQL如何支持部署SKLearn,Tensorflow,MLLib模型提供API预测服务
- TensorFlow模型部署到Android,需要注意几点
- keras中如何保存model的数据,以及如何重构模型进行数据预测
- 防止训练模型时信息丢失,用于TensorFlow、Keras和PyTorch的检查点教程
- 使用神经计算棒二代在OpenVino下推理基于Keras转换的TensorFlow 模型
- SSIS教程:创建简单的ETL包 -- 5. 添加包部署模型的包配置(Adding Package Configurations for the Package Deployment Model)
- tensorflow入门9 模型部署2
- 将tensorflow训练好的模型部署成sercice服务,并做预测
- keras系列︱Sequential与Model模型、keras基本结构功能(一)