2017-06-14 347 views
1

我檢討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」屬性?謝謝。

回答

2

'...由於形狀不完整而沒有觸發統計信息「意味着您對某些變量有未知的[形狀]信息,例如,當處理變量批量大小([無]的形狀),或者任意時間量的tf.while_loop等

因此官方tfprof文檔(source):

  • 它必須知道RegisterStatistics('flops')的「形狀」信息來計算統計信息。如果僅在 運行時期間已知形狀,則建議通過-run_meta_path的 。 tfprof可以使用來自RunMetadata的運行時形狀 信息來填充丟失的形狀。

至於RunMetadata,有tf.RunMetadata()運在tensorflow,這應該是你所需要的。通常你將它傳遞給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) 

希望這會有所幫助。