Ejemplo n.º 1
0
parser.add_argument('--ng_method', type=str, default='CMA')
parser.add_argument('--lr', type=float, default=0.05)
parser.add_argument('--latent_noise', type=float, default=0.05)
parser.add_argument('--truncate', type=float, default=2.0)
parser.add_argument('--make_video', action='store_true')
parser.add_argument('--max_minibatch', type=int, default=9)
parser.add_argument('--num_samples', type=int, default=9)
args = parser.parse_args()

### ---- initialize necessary --- ###

# (1) pretrained generative model
model = BigGAN().cuda().eval()

# (2) variable creator
var_manager = VariableManager()

# (3) default l1 + lpips loss function
loss_fn = LF.ProjectionLoss()

target = image.read(args.fp, as_transformed_tensor=True, im_size=256)
weight = image.read(args.mask_fp, as_transformed_tensor=True, im_size=256)
weight = ((weight + 1.) / 2.).clamp_(0.3, 1.0)

fn = args.fp.split('/')[-1].split('.')[0]
save_dir = f'./results/biggan_256/{args.method}_{fn}_w_transform'

var_manager = VariableManager()

# (4) define input output variable structure. the variable name must match
# the argument name of the model and loss function call
parser.add_argument('--ng_method', type=str, default='CMA')
parser.add_argument('--lr', type=float, default=0.05)
parser.add_argument('--latent_noise', type=float, default=0.05)
parser.add_argument('--truncate', type=float, default=2.0)
parser.add_argument('--make_video', action='store_true')
parser.add_argument('--max_minibatch', type=int, default=9)
parser.add_argument('--num_samples', type=int, default=9)
args = parser.parse_args()

### ---- initialize necessary --- ###

# (1) pretrained generative model
model = BigGAN().cuda().eval()

# (2) variable creator
var_manager = VariableManager()

# (3) default l1 + lpips loss function
loss_fn = LF.ProjectionLoss()

target = image.read(args.fp, as_transformed_tensor=True, im_size=256)
weight = image.read(args.mask_fp, as_transformed_tensor=True, im_size=256)
weight = ((weight + 1.) / 2.).clamp_(0.3, 1.0)
class_lbl = 153

fn = args.fp.split('/')[-1].split('.')[0]
save_dir = f'./results/biggan_256/hybridng_{fn}'

var_manager = VariableManager()
loss_fn = LF.ProjectionLoss()
Ejemplo n.º 3
0
loss_mask[:, 64:-64, :].data += 1.0

weight = loss_mask


fn = filename.split('/')[-1].split('.')[0]
save_dir = f'./results/stylegan2_cars/hybridng_{args.ng_method}_{fn}'



model = StyleGAN2(search='z')
model = nn.DataParallel(model)
loss_fn = LF.ProjectionLoss()


var_manager = VariableManager()

var_manager.register(
                variable_name='z',
                shape=(512,),
                default=None,
                grad_free=True,
                distribution=dist.TruncatedNormalModulo(
                                            sigma=1.0,
                                            trunc=args.truncate
                                            ),
                var_type='input',
                learning_rate=args.lr,
                hook_fn=hook.Compose(
                            hook.NormalPerturb(sigma=args.latent_noise),
                            hook.Clamp(trunc=args.truncate),