Switch to Windows Containers
true
,否则会报错:no matching manifest for windows/amd64
以NER的BiLSTM-CRF模型为例:
import tensorflow as tf builder = tf.saved_model.builder.SavedModelBuilder('./pb/') inputs = { 'inputX': tf.saved_model.utils.build_tensor_info(model.inputX), # placeholder 'inputY': tf.saved_model.utils.build_tensor_info(model.inputY), # placeholder 'inputZ': tf.saved_model.utils.build_tensor_info(model.seq_lens) # placeholder } outputs = { 'prediction': tf.saved_model.utils.build_tensor_info(model.viterbi_sequence) } signature = tf.saved_model.signature_def_utils.build_signature_def( inputs, outputs, 'serving_default' ) builder.add_meta_graph_and_variables( sess, [tf.saved_model.tag_constants.SERVING], signature_def_map={'serving_default': signature} ) builder.save()
docker run tensorflow/serving
docker run -p 8501:8501 --mount type=bind,source=pb文件路径,target=/models/目标模型 -e MODEL_NAME=模型名 -t tensorflow/serving &
curl -X POST http://localhost:8501/v1/models/目标模型:predict -d '{"instances": [{"inputX":[21,20,60], "inputY": [0,0,0],"inputZ":30}]}'