1

I am currently trying to get a TF textsum model exported using the PREDICT SIGNATURE. I have _Decode returning a result from a passed in test article string and then I pass that to buildTensorInfo. This is in-fact a string being returned.

Now when I run the textsum_export.py logic to export the model, it gets to the point where is is building out the TensorInfo object however errors out with the below trace. I know that the PREDICT signature is usually used with images. Is this the problem? Can I not use this for the Textsum model because I am working with strings?

Error is:

Traceback (most recent call last):
  File "export_textsum.py", line 129, in Export
    tensor_info_outputs = tf.saved_model.utils.build_tensor_info(res)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/saved_model/utils_impl.py", line 37, in build_tensor_info
    dtype_enum = dtypes.as_dtype(tensor.dtype).as_datatype_enum
AttributeError: 'str' object has no attribute 'dtype'

The TF session where the model is exported is below:

with tf.Session(config = config) as sess:

                # Restore variables from training checkpoints.
                ckpt = tf.train.get_checkpoint_state(FLAGS.checkpoint_dir)
                if ckpt and ckpt.model_checkpoint_path:
                    saver.restore(sess, ckpt.model_checkpoint_path)
                    global_step = ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1]
                    print('Successfully loaded model from %s at step=%s.' %
                        (ckpt.model_checkpoint_path, global_step))
                    res = decoder._Decode(saver, sess)

                    print("Decoder value {}".format(type(res)))
                else:
                    print('No checkpoint file found at %s' % FLAGS.checkpoint_dir)
                    return

                # Export model
                export_path = os.path.join(FLAGS.export_dir,str(FLAGS.export_version))
                print('Exporting trained model to %s' % export_path)


                #-------------------------------------------

                tensor_info_inputs = tf.saved_model.utils.build_tensor_info(serialized_tf_example)
                tensor_info_outputs = tf.saved_model.utils.build_tensor_info(res)

                prediction_signature = (
                    tf.saved_model.signature_def_utils.build_signature_def(
                        inputs={ tf.saved_model.signature_constants.PREDICT_INPUTS: tensor_info_inputs},
                        outputs={tf.saved_model.signature_constants.PREDICT_OUTPUTS:tensor_info_outputs},
                        method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME
                        ))

                #----------------------------------

                legacy_init_op = tf.group(tf.tables_initializer(), name='legacy_init_op')
                builder = saved_model_builder.SavedModelBuilder(export_path)

                builder.add_meta_graph_and_variables(
                    sess=sess, 
                    tags=[tf.saved_model.tag_constants.SERVING],
                    signature_def_map={
                        'predict':prediction_signature,
                    },
                    legacy_init_op=legacy_init_op)
                builder.save()

                print('Successfully exported model to %s' % export_path)
2
  • 1
    PREDICT signature work with tensors, res_tensor = tf.convert_to_tensor(res) Commented Oct 21, 2017 at 13:43
  • Gaurav you are awesome! That worked perfectly. I can't seem to set this comment as the answer but you should be the one to get the credit. If you can provide your comment above as an answer I will accept it. Thanks again! Commented Oct 21, 2017 at 22:57

1 Answer 1

4

PREDICT signature work with tensors, if res is 'str' type python variable, then res_tensor will be of dtype tf.string

res_tensor = tf.convert_to_tensor(res) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.