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

Class SIMDCLModel

models/simdcl_model.py:10–299  ·  view source on GitHub ↗

This class implements DCLGAN with similarity loss. This code is inspired by CUT and CycleGAN.

Source from the content-addressed store, hash-verified

8
9
10class SIMDCLModel(BaseModel):
11 """
12 This class implements DCLGAN with similarity loss.
13 This code is inspired by CUT and CycleGAN.
14 """
15
16 @staticmethod
17 def modify_commandline_options(parser, is_train=True):
18 """ Configures options specific for SIMDCL.
19 """
20 parser.add_argument('--DCL_mode', type=str, default="SIM", choices='SIM')
21 parser.add_argument('--lambda_GAN', type=float, default=1.0, help='weight for GAN loss:GAN(G(X))')
22 parser.add_argument('--lambda_NCE', type=float, default=2.0, help='weight for NCE loss: NCE(G(X), X)')
23 parser.add_argument('--lambda_SIM', type=float, default=10.0, help='weight for NCE loss: NCE(G(X), X)')
24 parser.add_argument('--nce_idt', type=util.str2bool, nargs='?', const=True, default=False,
25 help='use NCE loss for identity mapping: NCE(G(Y), Y))')
26 parser.add_argument('--nce_layers', type=str, default='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'],
31 help='how to downsample the feature map')
32 parser.add_argument('--netF_nc', type=int, default=256)
33 parser.add_argument('--nce_T', type=float, default=0.07, help='temperature for NCE loss')
34 parser.add_argument('--num_patches', type=int, default=256, help='number of patches per layer')
35 parser.add_argument('--flip_equivariance',
36 type=util.str2bool, nargs='?', const=True, default=False,
37 help="useless")
38
39 parser.set_defaults(pool_size=0) # no image pooling
40
41 opt, _ = parser.parse_known_args()
42
43 # Set default parameters for SIMDCL.
44 if opt.DCL_mode.lower() == "sim":
45 parser.set_defaults(nce_idt=True, lambda_NCE=2.0)
46 else:
47 raise ValueError(opt.DCL_mode)
48
49 return parser
50
51 def __init__(self, opt):
52 BaseModel.__init__(self, opt)
53
54 # specify the training losses you want to print out.
55 # The training/test scripts will call <BaseModel.get_current_losses>
56 self.loss_names = ['D_A', 'G_A', 'NCE1', 'D_B', 'G_B', 'NCE2', 'G', 'Sim']
57 visual_names_A = ['real_A', 'fake_B']
58 visual_names_B = ['real_B', 'fake_A']
59 self.nce_layers = [int(i) for i in self.opt.nce_layers.split(',')]
60
61 if opt.nce_idt and self.isTrain:
62 self.loss_names += ['idt_B', 'idt_A']
63 visual_names_A.append('idt_A')
64 visual_names_B.append('idt_B')
65
66 self.visual_names = visual_names_A + visual_names_B # combine visualizations for A and B
67

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected