1

Ich erstellte ein LSTM RNN-Modell für die Textklassifizierung auf Tensorflow und exportierte das SavedModel erfolgreich. Ich habe das Modell mit savedModel CLI getestet und alles scheint gut zu funktionieren. Ich versuche jedoch, einen Client zu erstellen, der eine Anfrage stellen und ein Ergebnis erhalten kann. Ich habe diese tensorflow serving inception example (genauer inception_client.py) als Referenz verfolgt. Dies funktioniert gut mit dem Anfangsmodell, aber ich bin mir nicht sicher, wie ich die Anfrage für mein eigenes Modell ändern soll. Wie genau sollte ich die Anfrage ändern? Meine UnterschriftClient-Anforderung für Tensorflow-Serving gibt Fehler "Versuch, nicht initialisierten Wert full_connected/biases zu verwenden"

und das Modell zu speichern:

# Build the signature_def_map. 
classification_signature = signature_def_utils.build_signature_def(
    inputs={signature_constants.CLASSIFY_INPUTS: classification_inputs}, 
    outputs={ 
     signature_constants.CLASSIFY_OUTPUT_CLASSES: 
      classification_outputs_classes, 
    }, 
    method_name=signature_constants.CLASSIFY_METHOD_NAME) 

legacy_init_op = tf.group(
    tf.tables_initializer(), name='legacy_init_op') 
#add the sigs to the servable 
builder.add_meta_graph_and_variables(
    sess, [tag_constants.SERVING], 
    signature_def_map={ 
     signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: 
      classification_signature 
    }, 
    assets_collection=tf.get_collection(tf.GraphKeys.ASSET_FILEPATHS), 
    legacy_init_op=tf.group(assign_filename_op)) 



print ("added meta graph and variables") 

builder.save() 
print("model saved") 

Das Modell nimmt in inputs_ als die Eingabe, die eine Liste der Liste der Zahlen ([[1,3,4,5,2]]).

inputs_ = tf.placeholder(tf.int32, [None, None], name="input_ints") 

Wie kann ich die savedModel CLI bin mit (liefert richtige Ergebnisse):

$ saved_model_cli run --dir ./python2_SavedModelFinalInputInts --tag_set serve --signature_def 'serving_default' --input_exprs inputs='[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2634, 758, 938, 579, 1868, 1894, 24, 651, 572, 32, 1847, 232]]' 

Mehr Informationen über die savedModel:

$ saved_model_cli show --dir ./python2_prediction_SavedModelFinalInputInts --all 

MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs: 

signature_def['serving_default']: 
The given SavedModel SignatureDef contains the following input(s): 
inputs['inputs'] tensor_info: 
    dtype: DT_INT32 
    shape: (-1, -1) 
    name: inputs/input_ints:0 
The given SavedModel SignatureDef contains the following output(s): 
outputs['outputs'] tensor_info: 
    dtype: DT_FLOAT 
    shape: (1, 1) 
    name: predictions/fully_connected/Sigmoid:0 
Method name is: tensorflow/serving/predict 

Wie ich versuche, eine Anfrage in der erstellen Kundencode:

 request1 = predict_pb2.PredictRequest() 
     request1.model_spec.name = 'mnist' 
     request1.model_spec.signature_name = signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY 
    request1.inputs[signature_constants.PREDICT_INPUTS].CopyFrom(tf.contrib.util.make_tensor_proto(input_nums, shape=[1,100],dtype=tf.int32)) 

    response = stub.Predict(request1,1.0) 

    result_dict = { 'Analyst Rating': str(response.message) } 
    return jsonify(result_dict) 

ich die folgende Fehlermeldung erhalten:

[2017-11-29 19:03:29,318] ERROR in app: Exception on /analyst_rating [POST] 
Traceback (most recent call last): 
    File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1612, in full_dispatch_request 
    rv = self.dispatch_request() 
    File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1598, in dispatch_request 
    return self.view_functions[rule.endpoint](**req.view_args) 
    File "/usr/local/lib/python2.7/dist-packages/flask_restful/__init__.py", line 480, in wrapper 
    resp = resource(*args, **kwargs) 
    File "/usr/local/lib/python2.7/dist-packages/flask/views.py", line 84, in view 
    return self.dispatch_request(*args, **kwargs) 
    File "/usr/local/lib/python2.7/dist-packages/flask_restful/__init__.py", line 595, in dispatch_request 
    resp = meth(*args, **kwargs) 
    File "restApi.py", line 91, in post 
    response = stub.Predict(request,1) 
    File "/usr/local/lib/python2.7/dist-packages/grpc/beta/_client_adaptations.py", line 309, in __call__ 
    self._request_serializer, self._response_deserializer) 
    File "/usr/local/lib/python2.7/dist-packages/grpc/beta/_client_adaptations.py", line 195, in _blocking_unary_unary 
    raise _abortion_error(rpc_error_call) 
AbortionError: AbortionError(code=StatusCode.FAILED_PRECONDITION, details="Attempting to use uninitialized value fully_connected/biases 
    [[Node: fully_connected/biases/read = Identity[T=DT_FLOAT, _class=["loc:@fully_connected/biases"], _output_shapes=[[1]], _device="/job:localhost/replica:0/task:0/cpu:0"](fully_connected/biases)]]") 
127.0.0.1 - - [29/Nov/2017 19:03:29] "POST /analyst_rating HTTP/1.1" 500 - 
{"message": "Internal Server Error"} 

Update:

die Unterschrift des Modells aus einer Klassifizierung Signatur zu einer Vorhersage Signatur ändern schien zu funktionieren. Ich änderte auch das legacy_init_op zu legacy_init_op, wie es von assign_filename_op definiert wurde, das ich anfänglich für die Organisation von Assets verwendet hatte.

Antwort

0

Die Änderung der Modellsignatur von der Klassifizierung zu einer Vorhersagesignatur schien Ergebnisse zu liefern.

Ich bin mir nicht ganz sicher, wie die Clientanforderung für ein Modell mit Klassifizierungssignatur sein sollte oder warum es nicht funktionierte.

(Wenn jemand eine Erklärung hat, wähle ich das als die richtige Antwort.)

Verwandte Themen