import 各种包
seed = 0 # 设置一个种子,确保可以复现
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
torch.cuda.manual_seed_all(seed) # if you are using multi-GPU.
np.random.seed(seed) # Numpy module.
random.seed(seed) # Python random module.
torch.manual_seed(seed)
torch.backends.cudnn.benchmark = False
torch.backends.cudnn.deterministic = True
def train():
test_loader = DataLoader(dataset=test_dataset,batch_size=batch_size, shuffle=False, drop_last=False)
net.eval()
for i in range(epoch):
...
- seed设置
- shuffle=False
- net.eval() 打开
之所以每次在测试集上的结果不同的原因持续更新中。。。