2017-02-12 35 views
0

訓練有素我的網絡並保存最終的權重這樣的總結:我如何總結張恢復到一個變量

# ... 
weights_summaries.append(tf.summary.tensor_summary('out-weights', weights['out'])) 
# ... write summary 

現在我想用我的分類。我試圖從總結加載重量:

for e in tf.train.summary_iterator(summary_file): 
    for v in e.summary.value: 
     # ... 
     # found the node 
     elif v.node_name == 'out-weights': 
      weights['out'] = tf.Variable(v.tensor) 
      # it doesn't work! 
      weights['out'] = tf.Variable.from_proto(v) 
      # assert! 
      weights['out'] = tf.Variable.from_proto(v.tensor) 
      # assert! 
      weights['out'] = tf.Variable(tf.Tensor.from_proto(v.tensor)) 
      # Tensor.from_proto is not defined! 

那麼,我應該如何加載權重?我瞭解「全局」模型保存程序,但我更願意只保存我需要的數據。

由於提前, 亞歷山大

回答

0

最後,我已經找到了解決辦法:

def tensor_summary_value_to_variable(value): 
    fb = numpy.frombuffer(v.tensor.tensor_content, dtype = numpy.float32) 
    shape = [] 
    for d in v.tensor.tensor_shape.dim: 
     shape.append(d.size) 
    fb = fb.reshape(shape) 
    var = tf.Variable(fb) 
    return var 
0

如果你想在模型的一個子集,我會建議你使用在tf.train.Saverconstructorvar_list參數。

+0

謝謝你的建議。如果能夠從摘要中恢復權重,那將是非常好的, –