2021
07-17
07-17
使用tensorflow 实现反向传播求导
看代码吧~X=tf.constant([-1,-2],dtype=tf.float32)w=tf.Variable([2.,3.])truth=[3.,3.]Y=w*X#cost=tf.reduce_sum(tf.reduce_sum(Y*truth)/(tf.sqrt(tf.reduce_sum(tf.square(Y)))*tf.sqrt(tf.reduce_sum(tf.square(truth)))))cost=Y[1]*Yoptimizer=tf.train.GradientDescentOptimizer(1).minimize(cost)withtf.Session()assess:sess.run(tf.global_variables_initializer())print(sess.run(Y))print(sess.run(...
继续阅读 >