Nz, D, G, args, images=images, id_labels=id_labels, pose_labels=pose_labels) else: train_single_DRGAN(Nd, Np, Nz, D, G, args, dataset=mydataset) else: if args.batch_size % args.images_perID == 0: train_multiple_DRGAN(images, id_labels, pose_labels, Nd, Np, Nz, D, G, args) else: print( "Please give valid combination of batch_size, images_perID" ) exit() else: # pose_code = [] # specify arbitrary pose code for every image #pose_code = np.random.uniform(-1,1, (images.shape[0], Np)) pose_code = np.ones((images.shape[0], Np)) pose_code_ = np.zeros((images.shape[0], Np)) pose_code[range(images.shape[0]), 1] = 0 pose_code_[range(images.shape[0]), pose_labels] = 1 features = Generate_Image(images, pose_code, pose_code_, Nz, G, G, args)
args = parser.parse_args() # Load the Expert Network C = resnet50_ft( weights_path='Pretrained/VGGFace2/resnet50_ft_dims_2048.pth') print('VGGFace2 model built successfully') if (args.generate): evl_args_warning(args) print('\nLoading model from [%s]...' % args.snapshot) checkpoint = torch.load('{}_checkpoint.pth.tar'.format(args.snapshot)) D = FNM_model.Discriminator(args) G = FNM_model.Generator(args) D.load_state_dict(checkpoint['D_model']) G.load_state_dict(checkpoint['G_model']) Generate_Image(D, G, C, args) else: args.snapshot_dir = os.path.join( args.snapshot_dir, datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')) os.makedirs(args.snapshot_dir) args_warning(args) if args.resume: if os.path.isfile(args.resume): print("=> loading checkpoint '{}'".format(args.resume)) D = FNM_model.Discriminator(args) G = FNM_model.Generator(args) checkpoint = torch.load(args.resume) args.start_epoch = checkpoint['epoch'] D.load_state_dict(checkpoint['D_model']) G.load_state_dict(checkpoint['G_model'])
exit() else: D = multi_model.Discriminator(Nd, Np, channel_num) G = multi_model.Generator(Np, Nz, channel_num, args.images_perID) else: print('\nLoading model from [%s]...' % args.snapshot) try: D = torch.load('{}_D.pt'.format(args.snapshot)) G = torch.load('{}_G.pt'.format(args.snapshot)) except: print("Sorry, This snapshot doesn't exist.") exit() if not (args.generate): if not (args.multi_DRGAN): train_single_DRGAN(dataloader, Nd, Np, Nz, D, G, args) else: if args.batch_size % args.images_perID == 0: train_multiple_DRGAN(images, id_labels, pose_labels, Nd, Np, Nz, D, G, args) else: print( "Please give valid combination of batch_size, images_perID" ) exit() else: image_dir = '/home/home_data/jason/DR-GAN-11/test' Generate_Image(image_dir, Nz, Np, G, args)