dont reuse variables
This commit is contained in:
parent
a6c76da533
commit
e553093d3b
21
main.py
21
main.py
|
@ -182,17 +182,18 @@ for epoch in range(opt.niter):
|
||||||
real_cpu, _ = data
|
real_cpu, _ = data
|
||||||
netD.zero_grad()
|
netD.zero_grad()
|
||||||
batch_size = real_cpu.size(0)
|
batch_size = real_cpu.size(0)
|
||||||
input.data.resize_(real_cpu.size()).copy_(real_cpu)
|
|
||||||
|
inputv = Variable(input)
|
||||||
|
|
||||||
errD_real = netD(input)
|
errD_real = netD(inputv)
|
||||||
errD_real.backward(one)
|
errD_real.backward(one)
|
||||||
|
|
||||||
# train with fake
|
# train with fake
|
||||||
noise.data.resize_(batch_size, nz, 1, 1)
|
noise.resize_(opt.batchSize, nz, 1, 1).normal_(0, 1)
|
||||||
noise.data.normal_(0, 1)
|
noisev = Variable(noise)
|
||||||
fake = netG(noise)
|
fake = netG(noisev)
|
||||||
input.data.copy_(fake.data)
|
inputv.data.copy_(fake.data)
|
||||||
errD_fake = netD(input)
|
errD_fake = netD(inputv)
|
||||||
errD_fake.backward(mone)
|
errD_fake.backward(mone)
|
||||||
errD = errD_real - errD_fake
|
errD = errD_real - errD_fake
|
||||||
optimizerD.step()
|
optimizerD.step()
|
||||||
|
@ -205,9 +206,9 @@ for epoch in range(opt.niter):
|
||||||
netG.zero_grad()
|
netG.zero_grad()
|
||||||
# in case our last batch was the tail batch of the dataloader,
|
# in case our last batch was the tail batch of the dataloader,
|
||||||
# make sure we feed a full batch of noise
|
# make sure we feed a full batch of noise
|
||||||
noise.data.resize_(opt.batchSize, nz, 1, 1)
|
noise.resize_(opt.batchSize, nz, 1, 1).normal_(0, 1)
|
||||||
noise.data.normal_(0, 1)
|
noisev = Variable(noise)
|
||||||
fake = netG(noise)
|
fake = netG(noisev)
|
||||||
errG = netD(fake)
|
errG = netD(fake)
|
||||||
errG.backward(one)
|
errG.backward(one)
|
||||||
optimizerG.step()
|
optimizerG.step()
|
||||||
|
|
Loading…
Reference in New Issue