Example #1
0
N=0
ngf = 80
ndf = 80
netMix =NetUskip(ngf, nDep, nz, bSkip=skipConnections, nc=3, ncIn=3, bTanh=True, Ubottleneck=Ubottleneck)
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
print ("device",device)

netMix.load_state_dict(torch.load(model_path))
netMix.to(device)
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)
Example #2
0
                    fakebig, alpha, A, mixedbig = famosGeneration(targetMosaic, fixnoise, templates.unsqueeze(0), True)
                else:
                    fakebig, alpha, A, mixedbig = splitW(targetMosaic, fixnoise, templates.unsqueeze(0), famosGeneration)
            vutils.save_image(mixedbig,'%s/mixed_epoch_%03d_%s.jpg' % (opt.outputFolder, epoch,desc), normalize =True)
            if True:#
                vutils.save_image(alpha,'%s/alpha_epoch_%03d_%s.jpg' % (opt.outputFolder, epoch,desc), normalize=False)
                vutils.save_image(rgb_channels(A), '%s/blenda_epoch_%03d_%s.jpg' % (opt.outputFolder, epoch, desc), normalize=False)##already 01
                v=nn.functional.avg_pool2d(A.view(-1, 1, A.shape[2], A.shape[3]), int(16))
                vutils.save_image(v,'%s/blendaBW_epoch_%03d_%s.jpg' % (opt.outputFolder, epoch,desc), normalize=False)

            vutils.save_image(fakebig,'%s/mosaicBig_epoch_%03d_%s.jpg' % (opt.outputFolder, epoch,desc),normalize=True)

            ##RUN OUT-OF-SAMPLE
            with torch.no_grad():
                try:
                    im=getImage(opt.testImage, bDel=True)
                    if im.shape[2]>targetMosaic.shape[2] or im.shape[3]>targetMosaic.shape[3]:
                        print ("cropping to original mosaic size")
                        im=im[:,:,:targetMosaic.shape[2],:targetMosaic.shape[3]]
                    im=torch.cat([im,targetMosaic[:,3:5,:im.shape[2],:im.shape[3]]],1)##coords
                    print ("test image size",im.shape)
                    fixnoise2 = torch.FloatTensor(1, nz, im.shape[2] // 2 ** nDep,im.shape[3] // 2 ** nDep)
                    fixnoise2 = fixnoise2.to(device)
                    fixnoise2 =setNoise(fixnoise2)
                    fakebig,_,_,_= splitW(im, fixnoise2, templates.unsqueeze(0), famosGeneration)
                    vutils.save_image(fakebig, '%s/mosaicTransfer_epoch_%03d_%s.jpg' % (opt.outputFolder, epoch, desc), normalize=True)
                except Exception as e:
                    print ("test image error",e)

            for net in Gnets:
                net.train()