【发布时间】:2018-06-06 15:45:22
【问题描述】:
我使用 tf.estimator API 创建了一个浅层神经网络。我想要类似于在 TensorFlow 开发峰会 https://www.youtube.com/watch?time_continue=948&v=eBbEDRsCmv4 中解释的超参数搜索。
我找不到任何有关如何执行此操作的更新文档。我有以下代码(我会尽量简化):
# Define nn architecture
def neural_net(features):
input_layer = tf.cast(features['x'], tf.float32)
hidden_layer = nn_layer(input_layer, 10, 'hidden_layer', act=tf.nn.relu)
out_layer = nn_layer(hidden_layer, 2, 'out_layer', act=tf.nn.relu)
return out_layer
# Define model function
def model_fn(features, labels, mode):
# Build the neural network
logits = neural_net(features<9
with tf.name_scope('loss'):
# Define loss and optimizer
loss = tf.losses.sparse_softmax_cross_entropy(logits=logits, labels=labels)
# Configure the Training
if mode == tf.estimator.ModeKeys.TRAIN:
optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.001)
train_op = optimizer.minimize(
loss=loss,
global_step=tf.train.get_global_step())
return tf.estimator.EstimatorSpec(mode=mode, loss=loss, train_op=train_op)
nn_classifier = tf.estimator.Estimator(model_fn=model_fn)
train_input_fn = tf.estimator.inputs.numpy_input_fn(
x={"x": train_data},
y=train_labels,
batch_size=100,
num_epochs=None,
shuffle=True)
nn_classifier.train(
input_fn=train_input_fn,
steps=20000
)
执行此代码,我可以获得损失的摘要并在 Tensorboard 中观察它。但是想象一下我想获得不同的曲线。假设我想看看损失如何随着样本数量的变化而变化,所以我会训练两个具有不同样本大小的模型。或者两个具有不同架构的模型......随便。
如何在 Tensorboard 中获得这两条曲线?
【问题讨论】:
标签: python tensorflow machine-learning neural-network