2016-10-27 7 views
0

tf.contrib.learn.DNNLinearCombinedClassifier 모델의 내보내기 방법을 사용하여 모델을 저장 한 다음 모델에 예측을 요청하는 텐서 흐름 제공 클라이언트를 작성하고 싶습니다. 누군가가tf.contrib.learn 넓고 깊은 모델을 저장하여 tensorflow 제공에 제공하려면 어떻게해야합니까?

를 설명 할 수 :

  1. 방법 자습서 또는 사전에 훈련 된 추정의 다른 부분에서 input_fn의 결과에서 BaseEstimator.export에 대한 매개 변수를 만들려면?

  2. 을 생성하여 tensorflow 서버 인스턴스에 보내는 방법은 무엇입니까?

답변

1

여기에서 나는 간단한 자습서 Exporting and Serving a TensorFlow Wide & Deep Model을 작성했습니다.

  1. 가 추정 초기화 중에 사용되는 모든 기능의 목록으로 수출 기능을 정의합니다

    네 가지 단계가 있습니다 추정량을 내보내려면.

  2. create_feature_spec_for_parsing을 사용하여 기능 구성을 만듭니다.

  3. input_fn_utils.build_parsing_serving_input_fn을 사용하는 게재에 적합한 serving_input_fn을 빌드하십시오.

  4. export_savedmodel()을 사용하여 모델을 내 보냅니다.

    1. 작성하고/제공/폴더, 예를 들어, 어딘가에서 스크립트를 배치 :

    은 다음 세 단계를 수행 할 필요가 제대로 클라이언트 스크립트를 실행하려면/serving/tensorflow_serving/example/

  5. py_binary을 추가하여 해당 BUILD 파일을 만들거나 수정하십시오.

  6. 모델 서버를 빌드하고 실행하십시오. tensorflow_model_server.

  7. 추측을 위해 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 링크를 제공으로, 그게 내가 따를

0

) 좋은 것? serving_default 내 생각에 모델을 내보낼 때 생각합니다. 그러나 내보내기 코드는 언급하지 않았습니다. 정의하십시오.

+0

안녕하세요. 품질에 대한 답변을 제공하는이 [대답 방법] (http://stackoverflow.com/help/how-to-answer)을 읽어보십시오. – thewaywewere

+0

여기 ** [signature_constants] (https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/saved_model/signature_constants.py)에서 ** serving_default **를 찾을 수 있습니다. 통조림 측정기가이를 자동으로 정의합니다. – MtDersvan

관련 문제