Open geekmister opened 2 months ago
The sample code
import torch from torchvision import transforms from PIL import Image from models import create_model from options.test_options import TestOptions # 加载模型 opt = TestOptions().parse() opt.name = 'facades_label2photo_pretrained' opt.model = 'test' opt.no_dropout = True model = create_model(opt) model.setup(opt) # 加载图像 image_path = 'path_to_your_image.jpg' image = Image.open(image_path).convert('RGB') transform = transforms.Compose([ transforms.Resize((256, 256)), transforms.ToTensor(), transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)) ]) image = transform(image).unsqueeze(0) # 生成变老或变年轻的图像 with torch.no_grad(): output = model.netG(image) output_image = transforms.ToPILImage()(output.squeeze().cpu()) # 保存结果 output_image.save('output_image.jpg')
CycleGAN is not have python package, only provide source code way, and I need to pack a python package to use!
Solution steps:
The sample code