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

标签 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

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

最佳答案

最近我使用对象检测做了一些有趣的事情,也出现了这个错误,我在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): """创建一个函数来缩放 logits,然后应用 Tensorflow 函数。""" def Score_converter_fn(logits): cr = logit_scale cr = tf.constant([[cr]],tf.float32) 打印(logit_scale) 打印(逻辑) scaled_logits = tf.divide(logits, cr, name='scale_logits') #更改 logit_scale 返回 tf_score_converter_fn(scaled_logits, name='convert_scores') Score_converter_fn.__name__ = '%s_with_logit_scale' % ( tf_score_converter_fn.__name__) 返回score_converter_fn

然后进入research文件夹,运行

python setup.py 安装

那就OK了!

顺便问一下,我不知道你是否应该重新安装research文件夹中的slim,你最好也重新安装一下。

关于python - 运行export_inference_graph.py会给出类型差异错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47242485/

相关文章:

python - pyodbc Netezza 'ascii' 编解码器无法对位置 0-2 : ordinal not in range(128) 中的字符进行编码

python - MacOS Catalina 上的两种不同的 Python3 和两种不同的 Python2 安装

python - 对可变长度序列进行训练和预测

python - 为什么在tensorflow 2中使用tf.GradientTape进行训练与使用fit API进行训练有不同的行为?

python - 为什么在 Python 中使用 [e] * n(用于创建单个项目重复 n 次的列表)速度很快?

python - 如果API没有返回数据,如何跳到Python中的另一个循环?

python - 有 SimpleHTTPServer 的 Tornado 等效项吗?

tensorflow - 如何在 MonitoredTrainingSession 中获取 global_step?

tensorflow - Pytorch Autograd : what does runtime error "grad can be implicitly created only for scalar outputs" mean

python-3.x - 为什么在 tensorflow 中出现这个错误?