- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
此问题已被问到 here ,不同的是我的问题集中在Estimator
.
一些上下文:我们已经使用 estimator 训练了一个模型,并获得了在 Estimator input_fn
中定义的一些变量,该函数将数据预处理为批处理。现在,我们正在转向预测。在预测过程中,我们使用相同的 input_fn
读入和处理数据。 但是出错说变量(word_embeddings)不存在 (变量存在于 chkp 图中),这是 input_fn
中的相关代码位:
with tf.variable_scope('vocabulary', reuse=tf.AUTO_REUSE):
if mode == tf.estimator.ModeKeys.TRAIN:
word_to_index, word_to_vec = load_embedding(graph_params["word_to_vec"])
word_embeddings = tf.get_variable(initializer=tf.constant(word_to_vec, dtype=tf.float32),
trainable=False,
name="word_to_vec",
dtype=tf.float32)
else:
word_embeddings = tf.get_variable("word_to_vec", dtype=tf.float32)
else
被调用以在检查点加载变量。未能识别该变量表明 a) 范围使用不当; b) 图未恢复。只要
reuse
,我认为范围在这里并不重要设置正确。
input_fn
恢复。阶段。通常,通过调用
saver.restore(sess, "/tmp/model.ckpt")
来恢复图形。
reference .估算器调查
source code没有让我了解与恢复有关的任何信息,最好的方法是 MonitoredSession,它是培训的包装器。它已经从原始问题中延伸了很多,对我是否走在正确的道路上没有信心,如果有人有任何见解,我会在这里寻求帮助。
tf.estimator
内恢复图形, 通过
input_fn
或
model_fn
?
最佳答案
嗨,我认为您的错误仅仅是因为您没有在 tf.get_variable (at predict) 中指定形状,似乎即使要恢复变量,您也需要指定形状。
我用一个简单的线性回归估计器进行了以下测试,它只需要预测 x + 5
def input_fn(mode):
def _input_fn():
with tf.variable_scope('all_input_fn', reuse=tf.AUTO_REUSE):
if mode == tf.estimator.ModeKeys.TRAIN:
var_to_follow = tf.get_variable('var_to_follow', initializer=tf.constant(20))
x_data = np.random.randn(1000)
labels = x_data + 5
return {'x':x_data}, labels
elif mode == tf.estimator.ModeKeys.PREDICT:
var_to_follow = tf.get_variable("var_to_follow", dtype=tf.int32, shape=[])
return {'x':[0,10,100,var_to_follow]}
return _input_fn
featcols = [tf.feature_column.numeric_column('x')]
model = tf.estimator.LinearRegressor(featcols, './outdir')
model.train(input_fn(tf.estimator.ModeKeys.TRAIN), max_steps=10000)
preds = model.predict(input_fn(tf.estimator.ModeKeys.PREDICT))
print(next(preds))
关于tensorflow - `get_variable()` 无法识别 tf.estimator 的现有变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53480116/
如何将自定义初始化程序指定为 tf.get_variable() 的第三个参数?具体来说,我有一个变量 y,我想使用另一个(已经初始化的)变量 x 对其进行初始化。 使用 tf.Variable()
我想使用 tf.get_variable 创建一个变量,它应该用一个 numpy 数组初始化。 据我所知,有两种创建变量的方法,tf.Variable 和tf.get_variable。我们可以轻松地
看来 tf.get_variable不接受 Tensor仅用于形状 int .这与 tf.Variable 不同。可以接受Tensors .这是否正确,如果正确,是否有解决方法来获取 tf.get_v
我读过 tf.get_variable从这里 question以及 tensorflow 网站上提供的文档中的一些内容。但是,我仍然不清楚,无法在网上找到答案。 怎么样tf.get_variable工
我尝试恢复 session 并调用 get_variable()获取类型的对象 tf.Variable(根据 this answer )。 它无法找到变量。重现该案例的最小示例是 如下。 首先,创建一
用法语法清晰: decay = tf.constant(0.001, dtype=tf.float32) w = tf.get_variable(name='weight', shape=[512,
在这个 answer 中,我了解了 Variable 和 get_variable 之间的区别,但我遇到了另一种获取或创建 model_variable 变量的方法,然后我我很困惑何时使用 get_v
此问题已被问到 here ,不同的是我的问题集中在Estimator . 一些上下文:我们已经使用 estimator 训练了一个模型,并获得了在 Estimator input_fn 中定义的一些变
我正在尝试运行这行代码: var_init_1 = tf.get_variable("var_init_1", [1, 2], dtype=tf.int32, initializer=tf.zero
我的问题与此有关 Tensorflow: How to get a tensor by name? 我可以给操作命名。但实际上他们的名字不同。例如: In [11]: with tf.variable
试图了解 keras 优化器中的 SGD 优化代码 (source code)。在 get_updates 模块中,我们有: # momentum shapes = [K.int_shape(p) f
我正在修改的代码使用 tf.get_variable 作为权重变量,使用 tf.Variable 进行偏差初始化。经过一番搜索,似乎 get_variable 由于其在共享方面的可移植性而应该始终受到
我正在使用网络表单将一些数据写入 MySQL 数据库,当我从表单接收输入数据时,我将其存储在一个对象中; 但是当我尝试在 SQL 查询中使用此数据时,出现错误。 有人可以帮我吗? 谢谢 K 这是对象的
我使用 tf.Variable 创建了一个 tensorflow 变量。我想知道为什么如果我使用相同的名称调用 tf.get_variable 不会引发异常,并且会创建一个名称递增的新变量? impo
我正在尝试从 this site 熟悉 TensorFlow 框架通过玩弄线性回归 (LR)。 LR的源代码可以找到here ,名称为 03_linear_regression_sol.py。 一般来
我只是想了解 TensorFlow 的命名行为,但仍需要一些说明。我在一个项目中遇到了命名张量的麻烦,因为它们是在函数中预定义的,稍后会调用该函数。 所以我这里有下面的例子: import tenso
给定一些占位符张量x,使得: x = tf.placeholder(无, 100) 我想知道为什么: h = tf.zeros(shape = (tf.shape(x)[0], 50)) 可以工作,但
我是 Tensorflow 的新手,正在尝试实现生成对抗网络。我正在关注 this同样的教程,我们正在尝试使用生成模型生成像图像这样的 MNIST 数据集。但是,该代码似乎使用的是旧版本的 Tenso
我想用 numpy 值初始化我网络上的一些变量。为了这个例子考虑: init=np.random.rand(1,2) tf.get_variable('var_name',initializer=in
对于 tensorflow 我想使用 tf.Variable 创建一个 tf 变量 test = tf.Variable() 并使用tf.glorot_uniform_initializer()和 s
我是一名优秀的程序员,十分优秀!