tensorflow - 如何在Tensorflow中动态初始化变量?

标签 tensorflow

我想在 Tensorflow 中针对一批示例运行一些优化程序,并且我已经对这些变量进行了一些原始估计以进行优化。所以我想用这些估计值来初始化变量,而不是一些随机数或零。

所以我想知道如何才能做到这一点?请注意,这里的初始化值是依赖于样本的。我的计划是将初始化提供给某个占位符,然后从该占位符初始化变量,但这不起作用。

最佳答案

定义操作update_estimates = tf.assign(variable,estimated_value),其中estimated_value是将包含您的猜测的tf.placeholder以 numpy 数组的形式。

然后你做一个简单的 sess.run(update_estimates, feed_dict={estimated_value:numpy_array})

tf.get_variable() 可能非常有用,但对于初学者我建议不要这样做。

关于tensorflow - 如何在Tensorflow中动态初始化变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45922059/

相关文章:

python - TensorFlow:训练时参数不更新

python-3.x - tensorflow 导入错误: module 'imp' has no attribute 'find_module'

python - keras LSTM 应该在没有 input_shape 参数的情况下工作吗?

machine-learning - 需要回答一些与机器学习相关的问题吗?

python - python2.7中tf.gather_nd中的星号上升语法错误

audio - 可以使用Tensorflow学习和处理音频吗?

docker - docker如何运行tensorflow-serving及其模型?

python - Tensorflow:feed_dict 占位符是 Operation 而不是 Tensor

python - Tensorflow 的 Estimator.evaluate() : Is the accuracy "global" or specific to the batch it saw?

tensorflow - 在 AdamOptimizer 中使用动态学习率有意义吗?