Export tensorflow graph with export_saved_model
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.
python tensorflow tensorflow-serving google-cloud-ml
add a comment |
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.
python tensorflow tensorflow-serving google-cloud-ml
add a comment |
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.
python tensorflow tensorflow-serving google-cloud-ml
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.
python tensorflow tensorflow-serving google-cloud-ml
python tensorflow tensorflow-serving google-cloud-ml
asked Nov 13 '18 at 16:13
constantinopolskayaconstantinopolskaya
205
205
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Try this:
def serving_input_receiver_fn():
ink = tf.placeholder(dtype=tf.float32, shape=[None, None, 3], name='ink')
length = tf.placeholder(dtype=tf.int64, shape=[None, 1])
features = "ink": inks, "length": lengths
return tf.estimator.export.ServingInputReceiver(features, features)
An example payload would be:
"instances": ["ink": [[0.1, 1.0, 2.0]], "length":[[1]]]
or as input to gcloud predict --json-instances
:
"ink": [[0.1, 1.0, 2.0]], "length":[[1]]]
I didn't look into the actual code; if ink is generally going to hold a lot of floats, you may want to consider an alternative encoding system.
Thanks, added shape to features and disabled adding loss and optimizers for prediction mode and it worked!
– constantinopolskaya
Nov 13 '18 at 19:08
happy to hear it!
– rhaertel80
Nov 15 '18 at 21:43
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53285128%2fexport-tensorflow-graph-with-export-saved-model%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try this:
def serving_input_receiver_fn():
ink = tf.placeholder(dtype=tf.float32, shape=[None, None, 3], name='ink')
length = tf.placeholder(dtype=tf.int64, shape=[None, 1])
features = "ink": inks, "length": lengths
return tf.estimator.export.ServingInputReceiver(features, features)
An example payload would be:
"instances": ["ink": [[0.1, 1.0, 2.0]], "length":[[1]]]
or as input to gcloud predict --json-instances
:
"ink": [[0.1, 1.0, 2.0]], "length":[[1]]]
I didn't look into the actual code; if ink is generally going to hold a lot of floats, you may want to consider an alternative encoding system.
Thanks, added shape to features and disabled adding loss and optimizers for prediction mode and it worked!
– constantinopolskaya
Nov 13 '18 at 19:08
happy to hear it!
– rhaertel80
Nov 15 '18 at 21:43
add a comment |
Try this:
def serving_input_receiver_fn():
ink = tf.placeholder(dtype=tf.float32, shape=[None, None, 3], name='ink')
length = tf.placeholder(dtype=tf.int64, shape=[None, 1])
features = "ink": inks, "length": lengths
return tf.estimator.export.ServingInputReceiver(features, features)
An example payload would be:
"instances": ["ink": [[0.1, 1.0, 2.0]], "length":[[1]]]
or as input to gcloud predict --json-instances
:
"ink": [[0.1, 1.0, 2.0]], "length":[[1]]]
I didn't look into the actual code; if ink is generally going to hold a lot of floats, you may want to consider an alternative encoding system.
Thanks, added shape to features and disabled adding loss and optimizers for prediction mode and it worked!
– constantinopolskaya
Nov 13 '18 at 19:08
happy to hear it!
– rhaertel80
Nov 15 '18 at 21:43
add a comment |
Try this:
def serving_input_receiver_fn():
ink = tf.placeholder(dtype=tf.float32, shape=[None, None, 3], name='ink')
length = tf.placeholder(dtype=tf.int64, shape=[None, 1])
features = "ink": inks, "length": lengths
return tf.estimator.export.ServingInputReceiver(features, features)
An example payload would be:
"instances": ["ink": [[0.1, 1.0, 2.0]], "length":[[1]]]
or as input to gcloud predict --json-instances
:
"ink": [[0.1, 1.0, 2.0]], "length":[[1]]]
I didn't look into the actual code; if ink is generally going to hold a lot of floats, you may want to consider an alternative encoding system.
Try this:
def serving_input_receiver_fn():
ink = tf.placeholder(dtype=tf.float32, shape=[None, None, 3], name='ink')
length = tf.placeholder(dtype=tf.int64, shape=[None, 1])
features = "ink": inks, "length": lengths
return tf.estimator.export.ServingInputReceiver(features, features)
An example payload would be:
"instances": ["ink": [[0.1, 1.0, 2.0]], "length":[[1]]]
or as input to gcloud predict --json-instances
:
"ink": [[0.1, 1.0, 2.0]], "length":[[1]]]
I didn't look into the actual code; if ink is generally going to hold a lot of floats, you may want to consider an alternative encoding system.
answered Nov 13 '18 at 16:49
rhaertel80rhaertel80
6,10111532
6,10111532
Thanks, added shape to features and disabled adding loss and optimizers for prediction mode and it worked!
– constantinopolskaya
Nov 13 '18 at 19:08
happy to hear it!
– rhaertel80
Nov 15 '18 at 21:43
add a comment |
Thanks, added shape to features and disabled adding loss and optimizers for prediction mode and it worked!
– constantinopolskaya
Nov 13 '18 at 19:08
happy to hear it!
– rhaertel80
Nov 15 '18 at 21:43
Thanks, added shape to features and disabled adding loss and optimizers for prediction mode and it worked!
– constantinopolskaya
Nov 13 '18 at 19:08
Thanks, added shape to features and disabled adding loss and optimizers for prediction mode and it worked!
– constantinopolskaya
Nov 13 '18 at 19:08
happy to hear it!
– rhaertel80
Nov 15 '18 at 21:43
happy to hear it!
– rhaertel80
Nov 15 '18 at 21:43
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53285128%2fexport-tensorflow-graph-with-export-saved-model%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown