[英]How to restore a dictionary variable in TensorFlow?
我的模型中有一個字典變量
evaluation = {}
evaluation['accuracy'] = ...
evaluation['f1'] = ...
evaluation['precesion'] = ...
evaluation['recall'] = ....
訓練並保存模型后,我想加載已保存的元圖並還原變量。 我想按名稱從圖中獲取占位符
evaluation = graph.get_operation_by_name("evaluation").outputs[0]
然后可以使用它
evaluation = sess.run(evaluation, {input_x: ...})
我想我需要為變量設置一個名稱,但是當我嘗試
evaluation = tf.Variable({}, name="evaluation")
我收到以下錯誤
TypeError: Failed to convert object of type <type 'dict'> to Tensor. Contents: {}. Consider casting elements to a supported type.
張量流中沒有字典變量。 您的字典在python中,並且沒有存儲在tensorflow圖中。 如果要在加載圖形后使用字典,則必須重新創建它:
evaluation = {}
evaluation["placeholder_name"] = graph.get_tensor_by_name('placeholder_name:0')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.