Serving Tf Model With Variable Length Input
I am trying to serve my TF model with TF Serving. Here's the model's input I have: raw_feature_spec = { 'x': tf.io.VarLenFeature(tf.string), 'y': tf.io.VarLenFeature(tf.s
Solution 1:
You have a placeholder named input_example_tensor
in the transformed_features
. And also the sparse placeholder of TensorFlow doesn't work.
I solve this problem by representing each sparse tensor with 3 dense tensors in the receiver, namely indices, values, and shape then convert them to sparse tensor in features. For your case, you need to define the serving_input_fn
as following:
def serving_input_fn():
inputs = {
"x_indices": tf.placeholder(tf.int64, [None, 2]),
"x_vals": tf.placeholder(tf.string, [None, 2]),
"x_shape": tf.placeholder(tf.int64, [2]),
"y_indices": tf.placeholder(tf.int64, [None, 2]),
"y_vals": tf.placeholder(tf.string, [None, 2]),
"y_shape": tf.placeholder(tf.int64, [2]),
"z": tf.placeholder(tf.string, [None, 1])
}
fvs = {
"x": tf.SparseTensor(
inputs["x_indices"],
inputs["x_vals"],
inputs[x_shape]
),
"y": tf.SparseTensor(
inputs["y_indices"],
inputs["y_vals"],
inputs[y_shape]
),
"z": inputs["z"]
}
return tf.estimator.export.ServingInputReceiver(fvs, inputs)
I also want to ask you a question, how did you manage to train a model that has VarLenFeature with TensorFlow Keras, could you share this part with me? Currently, I'm training this kind of models with TensorFlow Estimator.
Post a Comment for "Serving Tf Model With Variable Length Input"