简体   繁体   English

使用张量流中的估计器修改神经网络权重

[英]Modifying Neural Network weights using estimators in tensorflow

I need to modify the weight values during the execution, more specifically between the compute_gradients() and apply_gradients() functions. 我需要在执行过程中修改权重值,尤其是在compute_gradients()和apply_gradients()函数之间。 I was able to modify the gradients themselves, but i could not change the weights. 我可以自己修改渐变,但是无法更改权重。

I'm using the tutorial for the Iris NN in tensorflow: https://github.com/tensorflow/models/blob/master/samples/core/get_started/custom_estimator.py , the only difference being that i changed the minimize() function for the compute_gradients() and the apply_gradients() function. 我正在使用Tensorflow中的Iris NN教程: https : //github.com/tensorflow/models/blob/master/samples/core/get_started/custom_estimator.py ,唯一的区别是我更改了minimal()该函数适用于compute_gradients()和apply_gradients()函数。

grads_and_vars = optimizer.compute_gradients(loss)
// some way to change the weights
train_op = optimizer.apply_gradients(grads_and_vars, global_step=tf.train.get_global_step())

Thanks in advance. 提前致谢。

My best guess is that you are looking for tf.assign (from here ) to assign values to your Variable tensors. 我的最佳猜测是,您正在寻找tf.assign (从此处开始 )以将值分配给Variable张量。

According to the docs: 根据文档:

Update 'ref' by assigning 'value' to it. 通过为其分配“值”来更新“参考”。

This operation outputs a Tensor that holds the new value of 'ref' after the value has been assigned. 分配该值后,此操作将输出一个保存新值“ ref”的张量。 This makes it easier to chain operations that need to use the reset value. 这使得链接需要使用重置值的操作变得更加容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM