2017-10-21 5 views
0

現在、PREDICT SIGNATUREを使用してエクスポートされたTFテキストモデルを取得しようとしています。 _Decodeは、渡されたテスト記事の文字列から結果を返してから、それをbuildTensorInfoに渡します。実際には文字列が返されます。TensorFlow Servingのテキストサムモデルをエクスポートするとき、 'str'オブジェクトに属性 'dtype'がありません

モデルをエクスポートするためにtextsum_export.pyロジックを実行すると、TensorInfoオブジェクトを構築しているポイントに到達しますが、以下のトレースでエラーが発生します。私は、PREDICT署名が通常画像とともに使用されることを知っています。これは問題ですか?文字列を扱っているので、これをTextsumモデルに使用できませんか?

エラーがある:

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' 

モデルがエクスポートされTFセッションは以下である:RESがある場合

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) 
+1

テンソル付きPREDICT署名作業 res_tensor = tf.convert_to_tensor(res) –

+0

Gauravあなたは素晴らしいです!それは完璧に働いた。私は答えとしてこのコメントを設定することはできませんが、あなたは信用を得るために1つでなければなりません。あなたが答えとして上記のあなたのコメントを提供できるなら、私はそれを受け入れるでしょう。再度、感謝します! – xtr33me

答えて

1

は、テンソルと署名作業を予測する 'STR' 型Pythonの変数は、res_tensor dtype tf.stringになります

res_tensor = tf.convert_to_tensor(res) 
関連する問題