여기에서 나는 간단한 자습서 Exporting and Serving a TensorFlow Wide & Deep Model을 작성했습니다.
가 추정 초기화 중에 사용되는 모든 기능의 목록으로 수출 기능을 정의합니다
네 가지 단계가 있습니다 추정량을 내보내려면.
create_feature_spec_for_parsing
을 사용하여 기능 구성을 만듭니다.
input_fn_utils.build_parsing_serving_input_fn
을 사용하는 게재에 적합한 serving_input_fn
을 빌드하십시오.
export_savedmodel()
을 사용하여 모델을 내 보냅니다.
작성하고/제공/폴더, 예를 들어, 어딘가에서 스크립트를 배치 :
은 다음 세 단계를 수행 할 필요가 제대로 클라이언트 스크립트를 실행하려면/serving/tensorflow_serving/example/
py_binary
을 추가하여 해당 BUILD 파일을 만들거나 수정하십시오.
모델 서버를 빌드하고 실행하십시오. tensorflow_model_server
.
추측을 위해 tensorflow_model_server
에 tf.Example을 보내는 클라이언트를 생성, 빌드 및 실행하십시오. 자세한 내용은
from grpc.beta import implementations
from tensorflow_serving.apis import predict_pb2
from tensorflow_serving.apis import prediction_service_pb2
tf.app.flags.DEFINE_string('server', 'localhost:9000', 'Server host:port.')
tf.app.flags.DEFINE_string('model', 'wide_and_deep', 'Model name.')
FLAGS = tf.app.flags.FLAGS
...
def main(_):
host, port = FLAGS.server.split(':')
# Set up a connection to the TF Model Server
channel = implementations.insecure_channel(host, int(port))
stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
# Create a request that will be sent for an inference
request = predict_pb2.PredictRequest()
request.model_spec.name = FLAGS.model
request.model_spec.signature_name = 'serving_default'
# A single tf.Example that will get serialized and turned into a TensorProto
feature_dict = {'age': _float_feature(value=25),
'capital_gain': _float_feature(value=0),
'capital_loss': _float_feature(value=0),
'education': _bytes_feature(value='11th'.encode()),
'education_num': _float_feature(value=7),
'gender': _bytes_feature(value='Male'.encode()),
'hours_per_week': _float_feature(value=40),
'native_country': _bytes_feature(value='United-States'.encode()),
'occupation': _bytes_feature(value='Machine-op-inspct'.encode()),
'relationship': _bytes_feature(value='Own-child'.encode()),
'workclass': _bytes_feature(value='Private'.encode())}
label = 0
example = tf.train.Example(features=tf.train.Features(feature=feature_dict))
serialized = example.SerializeToString()
request.inputs['inputs'].CopyFrom(
tf.contrib.util.make_tensor_proto(serialized, shape=[1]))
# Create a future result, and set 5 seconds timeout
result_future = stub.Predict.future(request, 5.0)
prediction = result_future.result().outputs['scores']
print('True label: ' + str(label))
print('Prediction: ' + str(np.argmax(prediction)))
튜토리얼 자체보고 : 모델이 Estimator.export_savedmodel()
를 사용하여 내 보낸 성공적으로 자체 봉사 TensorFlow를 구축하는 경우
, 여기에 당신이 할 수있는 무언가이다.
희망이 있습니다.
P. 이 유형의 질문에는 중복이 4 개 이상 있습니다.당신이 서명을 정의 https://github.com/MtDersvan/tf_playground/blob/master/wide_and_deep_tutorial/wide_and_deep_basic_serving.md
: 높은 담당자 가진 사람을 닫거나 그룹 수 있다면 당신은뿐만에 refrence 링크를 제공으로, 그게 내가 따를
안녕하세요. 품질에 대한 답변을 제공하는이 [대답 방법] (http://stackoverflow.com/help/how-to-answer)을 읽어보십시오. – thewaywewere
여기 ** [signature_constants] (https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/saved_model/signature_constants.py)에서 ** serving_default **를 찾을 수 있습니다. 통조림 측정기가이를 자동으로 정의합니다. – MtDersvan