- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我已经创建了以下训练模型,并希望在 Tensorboard 上将其可视化:
## Basic Cell LSTM tensorflow
index_in_epoch = 0;
perm_array = np.arange(x_train.shape[0])
np.random.shuffle(perm_array)
# function to get the next batch
def get_next_batch(batch_size):
global index_in_epoch, x_train, perm_array
start = index_in_epoch
index_in_epoch += batch_size
if index_in_epoch > x_train.shape[0]:
np.random.shuffle(perm_array) # shuffle permutation array
start = 0 # start next epoch
index_in_epoch = batch_size
end = index_in_epoch
return x_train[perm_array[start:end]], y_train[perm_array[start:end]]
# parameters
n_steps = seq_len-1
n_inputs = 4
n_neurons = 200
n_outputs = 4
n_layers = 2
learning_rate = 0.001
batch_size = 50
n_epochs = 100
train_set_size = x_train.shape[0]
test_set_size = x_test.shape[0]
tf.reset_default_graph()
X = tf.placeholder(tf.float32, [None, n_steps, n_inputs])
y = tf.placeholder(tf.float32, [None, n_outputs])
# use LSTM Cell with peephole connections
layers = [tf.contrib.rnn.LSTMCell(num_units=n_neurons,
activation=tf.nn.leaky_relu, use_peepholes = True)
for layer in range(n_layers)]
multi_layer_cell = tf.contrib.rnn.MultiRNNCell(layers)
rnn_outputs, states = tf.nn.dynamic_rnn(multi_layer_cell, X, dtype=tf.float32)
stacked_rnn_outputs = tf.reshape(rnn_outputs, [-1, n_neurons])
stacked_outputs = tf.layers.dense(stacked_rnn_outputs, n_outputs)
outputs = tf.reshape(stacked_outputs, [-1, n_steps, n_outputs])
outputs = outputs[:,n_steps-1,:] # keep only last output of sequence
loss = tf.reduce_mean(tf.square(outputs - y)) # loss function = mean squared error
optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate)
training_op = optimizer.minimize(loss)
# run graph
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for iteration in range(int(n_epochs*train_set_size/batch_size)):
x_batch, y_batch = get_next_batch(batch_size) # fetch the next training batch
sess.run(training_op, feed_dict={X: x_batch, y: y_batch})
if iteration % int(5*train_set_size/batch_size) == 0:
mse_train = loss.eval(feed_dict={X: x_train, y: y_train})
mse_valid = loss.eval(feed_dict={X: x_valid, y: y_valid})
print('%.2f epochs: MSE train/valid = %.6f/%.6f'%(
iteration*batch_size/train_set_size, mse_train, mse_valid))
我想知道如何查看权重和偏差以及我为训练提供的输入之间的相关性。
请帮帮我。如果我的问题没有答案,请告诉我是否有任何建议。请询问我是否需要任何东西,我会得到它并告诉你。
最佳答案
我认为在 Tensorboard 上可视化权重的最简单方法是将它们绘制为直方图。例如,您可以按如下方式记录图层。
for i, layer in enumerate(layers):
tf.summary.histogram('layer{0}'.format(i), layer)
为要记录的每个层或变量创建摘要后,您必须使用 merge_all 函数将它们全部收集起来并创建一个 FileWriter。
merged = tf.summary.merge_all()
writer = tf.summary.FileWriter('directory_name', sess.graph)
最后,您必须与其他操作一起运行摘要并将结果添加到您的作者。
summary, _ = sess.run([merged, training_op], feed_dict={X: x_batch, y: y_batch})
writer.add_summary(summary, iteration_number)
如果您想进一步分析您的权重,我建议将它们恢复为 numpy 数组,如 here 所述.
不过,我不知道有什么简单的方法可以在 Tensorboard 上绘制相关性。如果您只想获得输入的相关性,如果您的数据集不是很大,我建议您使用 scikit 或什至 pandas ( .corr function )。
希望对您有所帮助。也可以引用这个tutorial以获得更深入的解释。
关于python - 如何使用python在Tensorboard上显示模型的权重和偏差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52112771/
我正在用 Objective C 重写蒙特卡罗模拟,以便在 VBA/Excel 的 dll 中使用。计算中的“引擎”是创建 0 到 10001 之间的随机数,并将其与 5000-7000 附近的变量进
我目前正在尝试使用 Flask 创建一个简单的 Web 应用程序,用于交互式神经网络训练。我正在努力解决的是在训练前馈神经网络后检索隐藏层的权重 - 我的目标是为 Tensorflow's Playg
我知道如何找到手机当前所在位置的真实航向/磁航向,但是否有可能找到远程位置的磁偏差/磁偏角? 我想做的是能够在 map 上的一个地方放置一个图钉,然后找到真实的方位角和从该点开始有磁差的方位角。 谢谢
函数方法glTexImage2D将“level”作为参数,表示细节级别偏差。但是,可以使用 glTexParameteri 和 GL_TEXTURE_LOD_BIAS 目标来设置纹理的 LOD 偏差。
有没有一种简单的方法来显示我在训练后输入到使用 Neurolab 开发的 ANN 中的每个属性的偏差或权重? 最佳答案 是的,您可以看到所有图层的权重和偏差。通过使用 net.layers[i].np
我正在用我目前在 Metal 中使用的应用程序的 Android 版本重写一个 OpenGL 过滤器。它使用以下纹理查找函数:vec4 texture2D(sampler2D 采样器,vec2 坐标,
我有一个简单的算法,可以让对象在 Java 中以给定的最大速度跟随鼠标指针。该算法的关键在于: // Set up displacement trackers for later. // (These
我在我的 Android 应用程序中使用“HelveticaNeue.ttf”作为自定义字体;对于所有以前的 android 版本都很好,但是对于 lollipop,它比通常的字体拉伸(stretch
我正在寻找一种方法来生成一组具有指定均值和标准差的整数。偏差。 使用随机库,可以生成一组以高斯方式分布的随机 double ,这看起来像这样: #include std::tr1::normal_d
我正在尝试训练 LambdaMART 模型来对对象列表执行成对排序。我的训练数据集由 50,000 个 112 维特征向量组成。每个特征都由一个非负整数编码。 目标值是正整数(不连续)。给定两个新实例
我在名为“df”的数据框中有时间序列数据,并且计算 z 分数的代码如下: mean = df.mean() standard_dev = df.std() z_score = (df - mean)
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 3 年前。 Improve th
我正在尝试在 TensorFlow 中执行以下线性回归,但我的输出都是 Inf 和 NaN。 我的输入数据集必须是 Y=0.5*X + 2 + 噪声;其中 X 是大小 (1000) 的正态分布,噪声是
我是一名优秀的程序员,十分优秀!