我试图了解张量板如何可视化图表。为此,我使用了一个简单的线性回归。这是我的代码:
# LINEAR REGRESSION IN TENSORFLOW
# generate points
import numpy as np
import os
import time
import tensorflow as tf
num_points = 1000
vectors_set = []
for i in xrange(num_points):
x1 = np.random.normal(0.0, 0.55)
y1 = x1 * 0.1 + 0.3 + np.random.normal(0.0, 0.03)
vectors_set.append([x1, y1])
with tf.name_scope('data') as scope:
x_data = [v[0] for v in vectors_set]
y_data = [v[1] for v in vectors_set]
# Cost function and gradient descent algorithm
with tf.name_scope('model') as scope:
W = tf.Variable(tf.random_uniform([1], -1, 1), name = "W")
b = tf.Variable(tf.zeros([1]), name = "b")
z = tf.add(W * x_data, b, name = "z")
with tf.name_scope('loss') as scope:
loss = tf.reduce_mean(tf.square(z - y_data))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)
# Running the algorithm
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
timestamp = str(int(time.time()))
print timestamp
train_summary_writer = tf.train.SummaryWriter(
os.path.join(
"./", "summaries", timestamp), sess.graph)
train_summary_writer.add_graph(sess.graph)
我的问题是:
- 我没有在我的图表中定义渐变。它默认带有张量板吗?
- 为什么从损失到梯度有 8 个张量?为什么从模型到梯度有 5 个张量?
- 我没有定义变量 y。张量板会自动将 y 分配给常量吗?我怎样才能改变它?
- 为什么我的图表没有显示操作之间的箭头?
非常感谢!