Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
82 views
in Technique[技术] by (71.8m points)

python - Tensorflow Serving Predictions for ANTIQUE dataset

I am following Tensorflow Ranking ANTIQUE example Tutorial: TF-Ranking for sparse features and I am interested in getting the predictions with Tensorflow Serving. I first change the code and added the following function

def make_serving_input_fn():
    context_feature_spec = tf.feature_column.make_parse_example_spec(context_feature_columns().values())
    example_feature_spec = tf.feature_column.make_parse_example_spec(example_feature_columns().values())
  
    feature_spec = {}
    feature_spec.update(example_feature_spec)
    feature_spec.update(context_feature_spec)
    return tf.estimator.export.build_parsing_serving_input_receiver_fn(
        feature_spec)

In addition, I added an export:

eval_spec =  tf.estimator.EvalSpec(
          name="eval",
          input_fn=eval_input_fn,
          exporters=tf.estimator.LatestExporter(
            "latest_exporter",
            serving_input_receiver_fn=make_serving_input_fn()),
          throttle_secs=15)

In order to make the model run, I ran the following command:


docker run -it -p 8501:8501 --mount type=bind,source=/home/code/models/antique/export/latest_exporter/1612010189,target=/models/antique/1/ -e MODEL_NAME=antique -t tensorflow/serving

For the prediction, I added the following code:

def predict(instances): 
    request = predict_pb2.PredictRequest()
    t_proto = tf.make_tensor_proto(instances)
    request.inputs['examples'].CopyFrom(t_proto)
    request.model_spec.signature_name = 'predict'
    request.model_spec.name = 'antique'

    tf_serve_host ="172.17.0.3:8500"
    timeout_in_secs = 100  
    channel = insecure_channel(tf_serve_host)
    stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)

    result = stub.Predict(request, timeout_in_secs)
    predictions = np.array(result.outputs['output'].float_val)

    return predictions

However when I try to get predictions:

raw_dataset = tf.data.TFRecordDataset([DATA_PATH])
for e in raw_dataset.take(1):
    ELWC = input_pb2.ExampleListWithContext()
    single_example = ELWC.FromString(e.numpy())

And then:

predict([single_example.SerializeToString()])

I am getting the following error:

_InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
    status = StatusCode.INVALID_ARGUMENT
    details = "Could not parse example input, value: '
à)
Y)
?
document_tokensà
?
pit
bulls
are
a
lot
of
things
-
loyal
,
friendly
,
active
-
but
they
'
re

not
    naturally

aggressive
toward
people
.
since
they
were
bred
to
fight
other
animals
,
it
was
    important
that
they
not
snap
at
their
human
handler
##s
.
you
'
ve
fallen
for
a
common
myth
.

    relevance

?
document_input_mask??
€
?
document_input_ids??
?eò4?^è?í-ó′Eò?*òùó??íDé¤? I???à??ejD??D òù????é…Pü?áμü??áí?í)??¥S?f

document_id

    3971195_0
¨ 
document_bert_encoder_outputs? ? 
€ ìL?áòa?!~x?Vwo>Q?°?1>?o??#?-?GV?è$w??ì?>1}?f?z???[???>|$?K2I??êl?3??>?v?t[?1üi???L??_{?sA->Ny|? )?”—????m??üló>???{?à>[?/1_?aT
??Dt?x|x?Fi-???r??F...TRUNCATED"
    debug_error_string = "{"created":"@1612356404.796216049","description":"Error received from peer ipv4:172.17.0.3:8500","file":"src/core/lib/surface/call.cc","file_line":1061,"grpc_message":"Could not parse example input, value: '
u00e0)
u00dd)
u00d4u0002
u000fdocument_tokensu0012u00c0u0002
u00bdu0002
u0003pit
u0005bulls
u0003are
u0001a
u0003lot
u0002of
u0006things
u0001-
u0005loyal
u0001,
friendly
u0001,
u0006active
u0001-
u0003but
u0004they
u0001'
u0002re
u0003not
naturally

aggressive
u0006toward
u0006people
u0001.
u0005since
u0004they
u0004were
u0004bred
u0002to
u0005fight
u0005other
u0007animals
u0001,
u0002it
u0003was
important
u0004that
u0004they
u0003not
u0004snap
u0002at
u0005their
u0005human
u0007handler
u0003##s
u0001.
u0003you
u0001'
u0002ve
u0006fallen
u0003for
u0001a
u0006common
u0004myth
u0001.
u0012
relevanceu0012u0005u001au0003
u0001u0002
u009eu0001
u0013document_input_masku0012u0086u0001u001au0083u0001
u0080u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0001u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000
u00d5u0001
u0012document_input_idsu0012u00beu0001u001au00bbu0001
u00b8u0001eu00f24u00a1^u00e8u000fu008du009bu0016u00cdu000fu00adu0013u00f3u0007u00b4Eu00f2u0007u0083*u00f2u0007u00d9u0018u00f3u0007u00e5u000fu00ebu000fu00edu0007u00d0u0010u00e9u000fu00a4?u00a0Iu00d6u0014u00bfu0010u00f4u0007u00e0u0010u00ebu000fu00e4u000fu00f0ju00d0u000fu008au0017u008cu0010u00d0 u00f2u0007u00d9u000fu00d1u000fu009eu0014u00d8u000fu00ebu000fu00e9u000fu0085Pu00dcu000fu00f5u000fu00e1u0013u00b5u00dcu0001u00dfu000fu00f4u0007u00e1u000fu00edu0007u0086u0012u00ed)u00d5u000fu008du0083u0015u00a5Su00f4u0007fu0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000u0000
u001c
u000bdocument_idu0012
u000b
3971195_0
u00a8 
u001ddocument_bert_encoder_outputsu0012u0086 u0012u0083 
u0080 u0005u00ecLu00bfu00e1u00d2au00bf!~xu00bfVwo>Qu0006u0013?u00b0u00c4u00b9>u00efu00bau00f4u00be#?u00adu00beu009dGVu00bfu00c8$w?u009fu00ccu0088>1u008d}u00bffu00d5z?u00aeu00b6[u00bf\u00acu00e4>|u008d$u00bfK2I?u00c2u00eal?3?u009c>u001au00f4vu00bfu00feu001c[?1u00fci?u0083u00b6L?u00cf_{?sAu00ad>Ny|?u00a0)u007fu00bfu0094u0097u0015u00beu00f8u00c2u0011?mu00c2u001c?u00fclu00d3>u009fu0014u0005u00bfu00df{u007fu00bfu00e0u0017u0015>u0012u0090[u00bf/1_u00bfu00aau00de
u00bfu00d1Dtu00bfx|xu00bfFi-u00bfu00c4u00dfru00bfu00c4F...TRUNCATED","grpc_status":3}"
>

Can anybody help me what I am wrong?

question from:https://stackoverflow.com/questions/66046848/tensorflow-serving-predictions-for-antique-dataset

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...