本文介绍了如何从 tf.report_uninitialized_variables 获取未初始化的变量列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档说它是一维张量,但是,我无法弄清楚如何访问列表.

The documentation says it's a 1 d tensor, however, I have failed to figure out how to access the list.

我更喜欢实际变量而不是名称,因为我想通过 tf.variables_initializer()

I would prefer the actual variables rather than names as I would like to initialize them via tf.variables_initializer()

推荐答案

tf.report_uninitialized_variables() 为您提供一个带有变量名称的张量.所以它会比我的这里的解决方案更丑陋(在我看来).

您需要找到与您从 report_uninitialized_variables 获得的名称相对应的所有变量,并在您的 tf.variables_initializer() 中使用它们.像这样:

You will need to find all the variables corresponding to names you got from report_uninitialized_variables and they use them in your tf.variables_initializer(). Something like this:

tf.variables_initializer(
    [v for v in tf.global_variables() if v.name.split(':')[0] in set(sess.run(tf.report_uninitialized_variables()))
])

这篇关于如何从 tf.report_uninitialized_variables 获取未初始化的变量列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 07:33