如何在 Tensorflow 中使用 benchmark_model 时将布尔值传递给占位符?



我的模型的前两层是:

('#', 1, '#', '|Input Tensors {}|:', (<tf.Tensor 'import/Placeholder:0' shape=(5, 360, 480, 3) dtype=float32>,))
('#', 2, '#', '|Input Tensors {}|:', (<tf.Tensor 'import/phase_train:0' shape=<unknown> dtype=bool>,))

我想使用Tensorflow的基准测试工具对模型进行基准测试。我必须设置两个参数(浮点数和布尔值(。

我正在使用这样的基准测试工具:

bazel-bin/tensorflow/tools/benchmark/benchmark_model 
--graph=saved_model_fp32.pb 
--input_layer='Placeholder','phase_train' 
--input_layer_shape='5,360,480,3:0' 
--input_layer_type='float','bool' 
--output_layer='conv_decode1/cond/Merge' 
--show_run_order=false --show_time=false 
--show_memory=false --show_summary=false 
--show_flops=true #--logtostderr

但它抱怨我传递布尔值的方式:

2018-09-14 13:37:33.529605: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2018-09-14 13:37:33.561214: I tensorflow/tools/benchmark/benchmark_model.cc:492] Initialized session in 0.031689s
2018-09-14 13:37:33.561269: I tensorflow/tools/benchmark/benchmark_model.cc:323] Running benchmark for max 1 iterations, max -1 seconds without detailed stat logging, with -1s sleep between inferences
2018-09-14 13:37:33.979259: E tensorflow/tools/benchmark/benchmark_model.cc:302] Error during inference: Invalid argument: The second input must be a scalar, but it has shape [0]
[[Node: conv1/cond/Switch = Switch[T=DT_BOOL, _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_phase_train_0_1, _arg_phase_train_0_1)]]
2018-09-14 13:37:33.979956: I tensorflow/tools/benchmark/benchmark_model.cc:344] Failed on run 0
2018-09-14 13:37:33.979975: E tensorflow/tools/benchmark/benchmark_model.cc:562] Timing failed with Invalid argument: The second input must be a scalar, but it has shape [0]
[[Node: conv1/cond/Switch = Switch[T=DT_BOOL, _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_phase_train_0_1, _arg_phase_train_0_1)]]

我应该如何正确使用基准测试工具?

似乎直接的方法是定义一个同名的常量张量tf.constant(False, dtype=bool, shape=[], name='phase_train')并将其设置为代替phase_train占位符。

这对我有用:)

相关内容

  • 没有找到相关文章

最新更新