tensorflow - 如何在 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
占位符。
这对我有用:)
推荐阅读
- sql-server - 更新多个节点的 XML 数据
- dictionary - 如何分离元组、字典和列表
- javascript - 从不同的 HTML 标记中获取多个对应的值以在函数中使用
- mysql - 选择数据库中最高和最低的文章,如何?
- azure - 将服务器部署到 Azure 后 Azure 数据库变为只读
- r - 为什么在 r 中使用 group_by 和 summarise() 时出现“找不到对象”错误?
- python - 即使在关闭 pyqt 应用程序后,网络摄像头实例也没有被释放
- c++ - 类中 self 类型的对象 - TypeError: No to_python (by-value) converter found for C++ type
- javascript - JsTree - 在选择限制上禁用和启用复选框
- swift - 无法运行 Swift 包管理器 (macOS 10.14.4)