Exemple #1
0
# dataset_train = DIV2K(args.root, args.mask_root, img_tf, mask_tf, 'train')
# dataset_val = DIV2K(args.root, args.mask_root, img_tf, mask_tf, 'val')

iterator_train = iter(
    data.DataLoader(dataset_train,
                    batch_size=args.batch_size,
                    sampler=InfiniteSampler(len(dataset_train)),
                    num_workers=args.n_threads))
print(len(dataset_train))

model = PConvUNet()
if torch.cuda.device_count() > 1:
    print("Use", torch.cuda.device_count(), "GPUs!")
    model = nn.DataParallel(model)

model = model.to(device)

if args.finetune:
    lr = args.lr_finetune
    model.freeze_enc_bn = True
else:
    lr = args.lr

start_iter = 0
optimizer = torch.optim.Adam(filter(lambda p: p.requires_grad,
                                    model.parameters()),
                             lr=lr)
criterion = InpaintingLoss(VGG16FeatureExtractor()).to(device)

if args.resume:
    start_iter = load_ckpt(args.resume, [('model', model)],
Exemple #2
0
                    type=str,
                    default='../posewarp/data/hunter_256.jpeg')
parser.add_argument('--maskPath',
                    type=str,
                    default='../posewarp/data/hunter_256_IUV.npy')
#parser.add_argument('--maskPath', type=str, default='/home/cloudlet/vlr_824/project/backgroundInpainting/mask/003328.jpg')
parser.add_argument('--modelPath', type=str, default='./pretrainedModel.pth')
parser.add_argument('--image_size', type=int, default=256)
args = parser.parse_args()

device = torch.device('cuda')

size = (args.image_size, args.image_size)
img_transform = transforms.Compose([
    transforms.Resize(size=size),
    transforms.ToTensor(),
    transforms.Normalize(mean=opt.MEAN, std=opt.STD)
])
mask_transform = transforms.Compose(
    [transforms.Resize(size=size),
     transforms.ToTensor()])

dataset_val = customData(args.imPath, args.maskPath, img_transform,
                         mask_transform, 'val')

model = PConvUNet()
load_ckpt(args.modelPath, [('model', model)])
model.to(device)

model.eval()
evaluateCustom(model, dataset_val, device, 'result.jpg')