【问题标题】:Tensorflow what does "Incomplete shape" mean?TensorFlow“不完整的形状”是什么意思?
【发布时间】:2018-03-31 07:49:39
【问题描述】:

我正在查看 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”属性?谢谢。

【问题讨论】:

    标签: tensorflow


    【解决方案1】:

    ' ... no flops stats 由于不完整的形状'意味着您对某些变量有未知的 [shape] 信息,例如当您处理可变批量大小([None] 形状)或 tf.while_loop 任意时间等时。

    据官方tfprof docs (source):

    • RegisterStatistics('flops') 必须知道“形状”信息才能计算统计信息。这是 建议传入-run_meta_path,如果形状仅在 运行。 tfprof 可以用运行时形状填充缺失的形状 来自 RunMetadata 的信息。

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

    解决方案是在运行时传递 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)
    

    希望这会有所帮助。

    【讨论】:

    • 即使我已通过 run_metadata,我也会收到此消息。您的回答是否意味着只有 tfprof 在使用运行的输出时可以计算这个,但在运行本身期间,无论如何都会打印此警告?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多