Tensorflow“不完整的形状”是什么意思?

时间:2017-06-14 22:07:33

标签: tensorflow

我正在审查tensorflow日志并找到以下行:

4 ops no flops stats due to incomplete shapes. Consider passing run_meta to use run_time shapes.

此消息似乎来自following code

for op in graph.get_operations():
    try:
      stats = ops.get_stats_for_node_def(
          graph, op.node_def, REGISTERED_FLOP_STATS)
    except ValueError:
      # Catch Exception When shape is incomplete. Skip it.
      op_missing_shape += 1
      stats = None
  ......
  if op_missing_shape > 0 and not run_meta:
    sys.stderr.write('%d ops no flops stats due to incomplete shapes.\n' %
                     op_missing_shape)

在与GRU类似的情况下,日志中的这一行不会出现。所以我认为错误不是由批量大小引起的。你能解释一下它是什么吗?另外如何添加“run_meta”属性?感谢。

1 个答案:

答案 0 :(得分:4)

'...由于形状不完整而没有翻牌统计数据'意味着你有一些变量的未知[形状]信息,例如处理变量批量大小([无]形状)或tf.while_loop任意时间等时。

相对于官方tfprof文档(source):

  
      
  • 必须知道RegisterStatistics('flops')的“形状”信息才能计算统计数据。它是   建议传入-run_meta_path如果形状只是在期间知道   运行。 tfprof可以使用运行时形状填充缺少的形状   来自RunMetadata的信息。
  •   

至于RunMetadata,张量流中有一个tf.RunMetadata() op,应该是你需要的。通常您将其传递给sess.run()操作。

对此的解决方案是在运行时传递RunMetadata,此时将定义所有形状。

# Generate the RunMetadata that contains the memory and timing information.
#
# Note: When run on GPU, a kernel is first scheduled (enqueued) and then
#       executed asynchronously. tfprof only tracks the execution time.
#
run_metadata = tf.RunMetadata()
with tf.Session() as sess:
  _ = sess.run(train_op,
               options=tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE),
               run_metadata=run_metadata)

希望这有帮助。