netMix.eval() files = os.listdir(test_img_path) for f in files: if f == 'ying.jpg': t0 = time.time() print('picture_name:',f) im = getImage(os.path.join(test_img_path,f),bDel = True) im = im.to(device) mask = getImage('samples/ying_maskk_dilated.png',bDel = True) mask = mask.to(device) im1=im im = torch.mul(im,mask) fixnoise2 = torch.FloatTensor(1,nz, im.shape[2] // 2 ** nDep, im.shape[3] // 2 ** nDep) fixnoise2 = fixnoise2.to(device) fixnoise2=setNoise(fixnoise2) ''' else: if False: print('false') drift=(fixnoise2*1.0).uniform_(-1, 1) fixnoise2[:, zGL:fixnoise2.shape[1]-zPeriodic]+=0.05*drift[:, zGL:fixnoise2.shape[1]-zPeriodic] ''' fakebig =ganGeneration(im, fixnoise2) print(fakebig.shape) fakebig = fakebig print(f,"test image size", im.shape,"inference time", -t0+time.time())
content = content.to(device) if epoch==0 and i==0: print ("template size",templatePatch.shape) # train with real netD.zero_grad() text, _ = data batch_size = content.size(0)##if we use texture and content of diff size may have issue -- just trim text=text.to(device) output = netD(text)##used to find correct size for label errD_real = criterion(output, output.detach()*0+real_label) errD_real.backward() D_x = output.mean() # train with fake noise=setNoise(noise) fake, alpha, A, mixedI = famosGeneration(content, noise, templatePatch, True) output = netD(fake.detach())#???why detach errD_fake = criterion(output, output.detach()*0+fake_label) errD_fake.backward() if opt.fAdvM > 0: loss_adv_mixed = criterion(netD(mixedI.detach()), output.detach() * 0 + fake_label) loss_adv_mixed.backward() D_G_z1 = output.mean() errD = errD_real + errD_fake if opt.WGAN: gradient_penalty = calc_gradient_penalty(netD, text, fake[:text.shape[0]])##for case fewer text images gradient_penalty.backward()