MCPcopy Create free account
hub / github.com/JunlinHan/DCLGAN / FASTCUTModel

Class FASTCUTModel

models/fastcut_model.py:9–208  ·  view source on GitHub ↗

This class implements CUT and FastCUT model, described in the paper Contrastive Learning for Unpaired Image-to-Image Translation Taesung Park, Alexei A. Efros, Richard Zhang, Jun-Yan Zhu ECCV, 2020 The code borrows heavily from the PyTorch implementation of CycleGAN https://git

Source from the content-addressed store, hash-verified

7
8
9class FASTCUTModel(BaseModel):
10 """ This class implements CUT and FastCUT model, described in the paper
11 Contrastive Learning for Unpaired Image-to-Image Translation
12 Taesung Park, Alexei A. Efros, Richard Zhang, Jun-Yan Zhu
13 ECCV, 2020
14
15 The code borrows heavily from the PyTorch implementation of CycleGAN
16 https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix
17 """
18 @staticmethod
19 def modify_commandline_options(parser, is_train=True):
20 """ Configures options specific for FASTCUT model
21 """
22 parser.add_argument('--lambda_GAN', type=float, default=1.0, help='weight for GAN loss:GAN(G(X))')
23 parser.add_argument('--lambda_NCE', type=float, default=1.0, help='weight for NCE loss: NCE(G(X), X)')
24 parser.add_argument('--lambda_IDT', type=float, default=10.0, help='weight for NCE loss: NCE(G(X), X)')
25 parser.add_argument('--nce_idt', type=util.str2bool, nargs='?', const=True, default=False, help='use NCE loss for identity mapping: NCE(G(Y), Y))')
26 parser.add_argument('--nce_layers', type=str, default='0,4,8,12,16', help='compute NCE loss on which layers')
27 parser.add_argument('--nce_includes_all_negatives_from_minibatch',
28 type=util.str2bool, nargs='?', const=True, default=False,
29 help='(used for single image translation) If True, include the negatives from the other samples of the minibatch when computing the contrastive loss. Please see models/patchnce.py for more details.')
30 parser.add_argument('--netF', type=str, default='mlp_sample', choices=['sample', 'reshape', 'mlp_sample'], help='how to downsample the feature map')
31 parser.add_argument('--netF_nc', type=int, default=256)
32 parser.add_argument('--nce_T', type=float, default=0.07, help='temperature for NCE loss')
33 parser.add_argument('--num_patches', type=int, default=256, help='number of patches per layer')
34 parser.add_argument('--flip_equivariance',
35 type=util.str2bool, nargs='?', const=True, default=False,
36 help="Enforce flip-equivariance as additional regularization. It's used by FastCUT, but not CUT")
37
38 parser.set_defaults(pool_size=0) # no image pooling
39
40 opt, _ = parser.parse_known_args()
41
42 # Set default parameters for CUT and FastCUT
43 parser.set_defaults(
44 nce_idt=False, lambda_NCE=10.0, flip_equivariance=True,
45 n_epochs=150, n_epochs_decay=50
46 )
47
48 return parser
49
50 def __init__(self, opt):
51 BaseModel.__init__(self, opt)
52
53 # specify the training losses you want to print out.
54 # The training/test scripts will call <BaseModel.get_current_losses>
55 self.loss_names = ['G_GAN', 'D_real', 'D_fake', 'G', 'NCE']
56 self.visual_names = ['real_A', 'fake_B', 'real_B']
57 self.nce_layers = [int(i) for i in self.opt.nce_layers.split(',')]
58
59 if opt.nce_idt and self.isTrain:
60 self.loss_names += ['NCE_Y']
61 self.visual_names += ['idt_B']
62
63 if self.isTrain:
64 self.model_names = ['G', 'F', 'D']
65 else: # during test time, only load G
66 self.model_names = ['G']

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected