default=1, help='hyperparameter to blend wct feature and content feature') parser.add_argument('--gpu', type=int, default=0, help="which gpu to run on. default is 0") args = parser.parse_args() try: os.makedirs(args.outf) except OSError: pass # Data loading code dataset = Dataset(args.contentPath, args.stylePath, args.fineSize) loader = torch.utils.data.DataLoader(dataset=dataset, batch_size=1, shuffle=False) wct = WCT(args) def styleTransfer(contentImg, styleImg, imname, csF): sF5 = wct.e5(styleImg) cF5 = wct.e5(contentImg) sF5 = sF5.data.cpu().squeeze(0) cF5 = cF5.data.cpu().squeeze(0) csF5 = wct.transform(cF5, sF5, csF, args.alpha) Im5 = wct.d5(csF5)
def default_loader(path): return Image.open(path).convert('RGB') if __name__ == "__main__": model = ResNet_autoencoder(Bottleneck, DeconvBottleneck, [3, 4, 6, 3], 3).cuda() model.load_state_dict(torch.load(PATH)) model.eval() # Data loading code dataset = Dataset( "./content", "./style", ) loader = torch.utils.data.DataLoader(dataset=dataset, batch_size=1, shuffle=False) alpha_list = [0.4, 0.6, 0.7, 0.8, 1.0] for alpha in alpha_list: for i, (contentImg, styleImg, imname) in enumerate(loader): imname = imname[0] print('Transferring ' + imname) contentImg = contentImg.cuda() styleImg = styleImg.cuda() cImg = Variable(contentImg, volatile=True) sImg = Variable(styleImg, volatile=True) c, s = model.encoder(cImg), model.encoder(sImg)
type=int, default=-1, help="Multi = -1, else for specific level use level = {1,2,3,4,5}") parser.add_argument('--do_patches', type=bool, default=False) parser.add_argument('--kernel_size', type=int, default=512) parser.add_argument('--stride', type=int, default=512) args = parser.parse_args() try: os.makedirs(args.outf) except OSError: pass # Data loading code dataset = Dataset(args.contentPath, args.stylePath, args.fineSize, args.do_patches, args.kernel_size) loader = torch.utils.data.DataLoader(dataset=dataset, batch_size=1, shuffle=False) wct = WCT(args) def styleTransfer(contentImg, styleImg, imname, csF, level=-1, save_path=args.outf): # print("level= ",level) if (level == -1):
# parser.add_argument('--d3', default='../KD/Bin/models/small10x_decoder/3SD_10x_E29S5000.pth') # parser.add_argument('--d2', default='../KD/Bin/models/my_decoder/2BD_E30S0.pth') # parser.add_argument('--d1', default='../KD/Bin/models/my_decoder/1BD_E30S0.pth') args = parser.parse_args() try: os.makedirs(args.outf) except OSError: pass # Data loading code contentPath = args.UHD_contentPath if args.UHD else args.contentPath stylePath = args.UHD_stylePath if args.UHD else args.stylePath dataset = Dataset(contentPath, stylePath, args.texturePath, args.fineSize, args.picked_content_mark, args.picked_style_mark, args.synthesis) loader = torch.utils.data.DataLoader(dataset=dataset, batch_size=1, shuffle=False) logprint(args.log_mark) log = open("samples/log_%s_%s.txt" % (args.mode, args.log_mark), "w+") logprint(args._get_kwargs(), log) wct = WCT(args) @torch.no_grad() def styleTransfer(encoder, decoder, contentImg, styleImg, csF): # sF = encoder.forward_aux(styleImg)[-1]; torch.cuda.empty_cache()