def test_dcgan(self): # dcgan is flaky on some seeds, see: # https://github.com/ProjectToffee/onnx/pull/70 torch.manual_seed(1) if torch.cuda.is_available(): torch.cuda.manual_seed_all(1) netD = dcgan._netD(1) netD.apply(dcgan.weights_init) input = Variable(torch.randn(BATCH_SIZE, 3, dcgan.imgsz, dcgan.imgsz)) self.run_model_test(netD, train=False, batch_size=BATCH_SIZE, input=input) netG = dcgan._netG(1) netG.apply(dcgan.weights_init) state_dict = model_zoo.load_url(model_urls['dcgan_b'], progress=False) # state_dict = model_zoo.load_url(model_urls['dcgan_f'], progress=False) noise = Variable(torch.randn(BATCH_SIZE, dcgan.nz, 1, 1).normal_(0, 1)) self.run_model_test(netG, train=False, batch_size=BATCH_SIZE, input=noise, state_dict=state_dict, rtol=1e-2, atol=1e-6)
def test_dcgan(self): # note, could have more than 1 gpu netG = _netG(1) netG.apply(weights_init) netD = _netD(1) netD.apply(weights_init) input = torch.Tensor(bsz, 3, imgsz, imgsz) noise = torch.Tensor(bsz, nz, 1, 1) fixed_noise = torch.Tensor(bsz, nz, 1, 1).normal_(0, 1) fixed_noise = Variable(fixed_noise) netD.zero_grad() inputv = Variable(input) self.exportTest(toC(netD), toC(inputv), "dcgan-netD") noise.resize_(bsz, nz, 1, 1).normal_(0, 1) noisev = Variable(noise) self.exportTest(toC(netG), toC(noisev), "dcgan-netG")
def test_dcgan(self): # dcgan is flaky on some seeds, see: # https://github.com/ProjectToffee/onnx/pull/70 torch.manual_seed(1) if torch.cuda.is_available(): torch.cuda.manual_seed_all(1) netD = dcgan._netD(1) netD.apply(dcgan.weights_init) input = Variable(torch.randn(BATCH_SIZE, 3, dcgan.imgsz, dcgan.imgsz)) self.run_model_test(netD, train=False, batch_size=BATCH_SIZE, input=input) netG = dcgan._netG(1) netG.apply(dcgan.weights_init) state_dict = model_zoo.load_url(model_urls['dcgan_b'], progress=False) # state_dict = model_zoo.load_url(model_urls['dcgan_f'], progress=False) noise = Variable( torch.randn(BATCH_SIZE, dcgan.nz, 1, 1).normal_(0, 1)) self.run_model_test(netG, train=False, batch_size=BATCH_SIZE, input=noise, state_dict=state_dict, rtol=1e-2, atol=1e-6)
def test_dcgan_netD(self): netD = _netD(1) netD.apply(weights_init) input = Variable(torch.Tensor(bsz, 3, imgsz, imgsz).normal_(0, 1)) self.exportTest(toC(netD), toC(input))