我的模型中有一个字典变量
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.
答案 0 :(得分:1)
tensorflow中没有字典变量。你的字典是在python中,并没有存储在张量流图中。如果您在加载图表后想要字典,则必须重新创建它:
evaluation = {}
evaluation["placeholder_name"] = graph.get_tensor_by_name('placeholder_name:0')