运行export_inference_graph.py会给出类型错误的差异

时间:2017-11-11 20:28:59

标签: python tensorflow

我正在尝试通过执行export_inference_graph.py脚本导出模型。

我尝试使用我训练过的model.ckpt和ssd_mobilenet_v1_pets的官方示例文件。

在cmd中我输入:

python export_inference_graph.py \ --input_type image_tensor \ --pipeline_config_path training/ssd_mobilenet_v1_pets.config \ --trained_checkpoint_prefix training/model.ckpt-2453 \ --output_directory heart_graph

我正在使用TensorFlow 1.4并且我总是收到以下错误:

Traceback (most recent call last):
  File "export_inference_graph.py", line 119, in <module>
    tf.app.run()
  File "C:\Users\<Name>\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\platform\app.py", line 48, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "export_inference_graph.py", line 115, in main
    FLAGS.output_directory, input_shape)
  File "C:\Users\<Name>\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\models\research\object_detection\exporter.py", line 427, in export_inference_graph
    input_shape, optimize_graph, output_collection_name)
  File "C:\Users\<Name>\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\models\research\object_detection\exporter.py", line 353, in _export_inference_graph
    postprocessed_tensors = detection_model.postprocess(output_tensors)
  File "C:\Users\<Name>\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\models\research\object_detection\meta_architectures\ssd_meta_arch.py", line 405, in postprocess
    class_predictions_without_background)
  File "C:\Users\<Name>\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\models\research\object_detection\builders\post_processing_builder.py", line 94, in score_converter_fn
    scaled_logits = tf.divide(logits, logit_scale, name='scale_logits')
  File "C:\Users\<Name>\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\ops\math_ops.py", line 309, in divide
    return DivideDelegateWithName(x, name) / y
  File "C:\Users\<Name>\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\ops\math_ops.py", line 294, in __truediv__
    return _truediv_python3(self.x, y, self.name)
  File "C:\Users\<Name>\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\ops\math_ops.py", line 981, in _truediv_python3
    (x_dtype, y_dtype))
TypeError: x and y must have the same dtype, got tf.float32 != tf.int32

问题出在哪里以及如何解决?

1 个答案:

答案 0 :(得分:2)

最近我使用object detection做了一些有趣的事情,也发生了这个错误,我在github上查找问题并找到解决方案。

https://github.com/tensorflow/models/issues/2774中,有一个解决方案改变了源代码,我尝试了。它工作!!

您可以找到post_processing_builder.py并更改功能 def _score_converter_fn_with_logit_scale(tf_score_converter_fn, logit_scale): """Create a function to scale logits then apply a Tensorflow function.""" def score_converter_fn(logits): cr = logit_scale cr = tf.constant([[cr]],tf.float32) print(logit_scale) print(logits) scaled_logits = tf.divide(logits, cr, name='scale_logits') #change logit_scale return tf_score_converter_fn(scaled_logits, name='convert_scores') score_converter_fn.__name__ = '%s_with_logit_scale' % ( tf_score_converter_fn.__name__) return score_converter_fn

然后转到research文件夹,运行

python setup.py install

然后就可以了!

顺便说一句,我不知道您是否应该在slim文件夹中重新安装research,您最好重新安装它。