Yin*_*ong 2 variables rate tensorflow
我有一个训练模型
Y = w * X + b
Run Code Online (Sandbox Code Playgroud)
其中Y和X是输出和输入占位符,w和b是
我已经知道的矢量w的值只能是0或1,而b仍然是tf.float32.
在定义变量w时,如何量化变量w的范围?
或者
我可以有两种不同的学习率吗?w的比率为1或-1,b的比率通常为0.0001.
激活期间无法限制变量.但是你可以做的是在每次迭代后限制它.以下是一种方法tf.where():
import tensorflow as tf
a = tf.random_uniform(shape=(3, 3))
b = tf.where(
tf.less(a, tf.zeros_like(a) + 0.5),
tf.zeros_like(a),
tf.ones_like(a)
)
with tf.Session() as sess:
A, B = sess.run([a, b])
print A, '\n'
print B
Run Code Online (Sandbox Code Playgroud)
这会将高于0.5的所有内容转换为1,将其他所有内容转换为0:
[[ 0.2068541 0.12682056 0.73839438]
[ 0.00512838 0.43465161 0.98486936]
[ 0.32126224 0.29998791 0.31065524]]
[[ 0. 0. 1.]
[ 0. 0. 1.]
[ 0. 0. 0.]]
Run Code Online (Sandbox Code Playgroud)