1. PyTorch进行训练和测试时指定实例化的model模式为:train/eval
eg:
class VAE(nn.Module): def __init__(self): super(VAE, self).__init__() ... def reparameterize(self, mu, logvar): if self.training: std = logvar.mul(0.5).exp_() eps = Variable(std.data.new(std.size()).normal_()) return eps.mul(std).add_(mu) else: return mu model = VAE() ... def train(epoch): model.train() ... def test(epoch): model.eval()
View Code
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:Pytorch 细节记录 - Python技术站