怎样在一张表里比较不同参数组合?
先说出你的答案
定义边界、关键机制、一个反例;P8题再补容量、失败与验证。
查看完整题解
参考回答
直接回答
让每组参数对应一个独立试验目录,在 HParams 表里显示学习率、批大小与结果。先筛到训练和评估条件一致的试验,再按要优化的指标排序。
讲清原理
要判断一组参数稳不稳,可以按配置把不同种子的试验归在一起,在外部统计均值和波动。面板中最好保留单次结果,方便追到反常的某次训练。
例子与易错点
下面写两组学习率和示意分数,再读回同一个验证标签,核对表格要用的原始数值。
from pathlib import Path
from tempfile import TemporaryDirectory
directory = TemporaryDirectory()
root = Path(directory.name)
import tensorflow as tf
from tensorboard.backend.event_processing.event_accumulator import EventAccumulator
from tensorboard.plugins.hparams import api as hp
rate = hp.HParam("learning_rate", hp.Discrete([0.001, 0.01]))
header = tf.summary.create_file_writer(str(root))
with header.as_default():
hp.hparams_config([rate], [hp.Metric("val/accuracy")])
header.close()
for label, value, score in [("low", 0.001, 0.75), ("high", 0.01, 0.875)]:
writer = tf.summary.create_file_writer(str(root / label))
with writer.as_default():
hp.hparams({rate: value})
tf.summary.scalar("val/accuracy", score, step=1)
writer.close()
rows = {}
for label in ("low", "high"):
log = EventAccumulator(str(root / label)).Reload()
item, = log.Tensors("val/accuracy")
rows[label] = tf.make_ndarray(item.tensor_proto).item()
assert sorted(rows, key=rows.get, reverse=True) == ["high", "low"]
print("high ranks above low: 0.875 vs 0.75")
和评分标准对照,你能独立回答到哪一步?
自评会安排下一次复习,不保存你的口述内容。
这道题,你掌握得怎么样?
掌握程度由你主动标记,阅读和收藏不会自动改变状态。