1.为torch设置种子后,每次执行整个程序randn产生的随机数就会相同,网络初始化参数也会相同
myseed = 42069 # set a random seed for reproducibility
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
np.random.seed(myseed)
torch.manual_seed(myseed)
if torch.cuda.is_available():
torch.cuda.manual_seed_all(myseed)
2.torch中的method后面带有_表示原地操作,直接改变张量,如
init.xavier_uniform_(self.fc1.weight)
3.DATASET逻辑:外部csv文件==》numpy处理==》转换为pytorch
模型训练==》模型测试==》预测结果==》转回numpy==》写入csv文件
4.generator的意义是方便的由函数逻辑产生iterator,核心在于“简便”的iterator,就是generator
5.训练网络的early_stop原则:
每一个epoch训练结束后在验证集上进行测试,若验证集上loss低于之前的验证集loss,则保存当下模型参数,否则继续训练,直到early_stop_cnt轮后,模型在验证集上loss仍然没有更低的表现,则终止训练。(loss为验证集单个样本的平均loss/总loss)