I'm trying to train and deploy simplified Quick, Draw! classifier from here on Google Cloud. I've managed to train model in GC, now stuck at deploying it, more precisely, at creating serving input functions.
I'm following instructions from here and having tough times trying to understand what type of input tensor should be.
Error:
TypeError: Failed to convert object of type to Tensor. Contents: SparseTensor(indices=Tensor("ParseExample/ParseExample:0", shape=(?, 2), dtype=int64), values=Tensor("ParseExample/ParseExample:1", shape=(?,), dtype=float32), dense_shape=Tensor("ParseExample/ParseExample:2", shape=(2,), dtype=int64)). Consider casting elements to a supported type.
Serving function:
def serving_input_receiver_fn():
serialized_tf_example = tf.placeholder(dtype=tf.string, shape=[None], name='input_tensors')
receiver_tensors = {'infer_inputs': serialized_tf_example}
features = tf.parse_example(serialized_tf_example, feature_spec)
return tf.estimator.export.ServingInputReceiver(features, receiver_tensors)
Feature specification:
feature_spec = {
"ink": tf.VarLenFeature(dtype=tf.float32),
"shape": tf.FixedLenFeature([2], dtype=tf.int64)
}
Input layer:
def _get_input_tensors(features, labels):
shapes = features["shape"]
lengths = tf.squeeze(
tf.slice(shapes, begin=[0, 0], size=[params.batch_size, 1]))
inks = tf.reshape(features["ink"], [params.batch_size, -1, 3])
if labels is not None:
labels = tf.squeeze(labels)
return inks, lengths, labels
Code of model and training data were taken here.