3 ms·
I think the tensorflow code could be improved a bit if the author knew about the layers and loss modules. import tensorflow as tf import numpy as np X =
by dontreact 9y ago
I think the tensorflow code could be improved a bit if the author knew about the layers and loss modules.
import tensorflow as tf
import numpy as np
X = tf.placeholder("float")
Y = tf.placeholder("float")
pred = tf.layers.dense(X,use_bias=false)
cost = tf.losses.mean_squared_error(labels=Y,
predictions=pred)
optimizer =
tf.train.GradientDescentOptimizer(0.01).minimize(cost)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for t in range(10000):
x = np.array(np.random.random()).reshape((1, 1, 1, 1))
y = x * 3
(_, c) = sess.run([optimizer, cost], feed_dict={X: x, Y: y})
print c