This class implements DCLGAN model. This code is inspired by CUT and CycleGAN.
| 8 | |
| 9 | |
| 10 | class DCLModel(BaseModel): |
| 11 | """ This class implements DCLGAN model. |
| 12 | This code is inspired by CUT and CycleGAN. |
| 13 | """ |
| 14 | |
| 15 | @staticmethod |
| 16 | def modify_commandline_options(parser, is_train=True): |
| 17 | """ Configures options specific for DCLGAN """ |
| 18 | parser.add_argument('--DCL_mode', type=str, default="DCL", choices='DCL') |
| 19 | parser.add_argument('--lambda_GAN', type=float, default=1.0, help='weight for GAN loss:GAN(G(X))') |
| 20 | parser.add_argument('--lambda_NCE', type=float, default=2.0, help='weight for NCE loss: NCE(G(X), X)') |
| 21 | parser.add_argument('--lambda_IDT', type=float, default=1.0, help='weight for l1 identical loss: (G(X),X)') |
| 22 | parser.add_argument('--nce_idt', type=util.str2bool, nargs='?', const=True, default=False, |
| 23 | help='use NCE loss for identity mapping: NCE(G(Y), Y))') |
| 24 | parser.add_argument('--nce_layers', type=str, default='4,8,12,16', help='compute NCE loss on which layers') |
| 25 | parser.add_argument('--nce_includes_all_negatives_from_minibatch', |
| 26 | type=util.str2bool, nargs='?', const=True, default=False, |
| 27 | 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.') |
| 28 | parser.add_argument('--netF', type=str, default='mlp_sample', choices=['sample', 'reshape', 'mlp_sample'], |
| 29 | help='how to downsample the feature map') |
| 30 | parser.add_argument('--netF_nc', type=int, default=256) |
| 31 | parser.add_argument('--nce_T', type=float, default=0.07, help='temperature for NCE loss') |
| 32 | parser.add_argument('--num_patches', type=int, default=256, help='number of patches per layer') |
| 33 | parser.add_argument('--flip_equivariance', |
| 34 | type=util.str2bool, nargs='?', const=True, default=False, |
| 35 | help="Enforce flip-equivariance as additional regularization.") |
| 36 | |
| 37 | parser.set_defaults(pool_size=0) # no image pooling |
| 38 | |
| 39 | opt, _ = parser.parse_known_args() |
| 40 | |
| 41 | # Set default parameters for DCLGAN. |
| 42 | if opt.DCL_mode.lower() == "dcl": |
| 43 | parser.set_defaults(nce_idt=True, lambda_NCE=2.0) |
| 44 | else: |
| 45 | raise ValueError(opt.DCL_mode) |
| 46 | |
| 47 | return parser |
| 48 | |
| 49 | def __init__(self, opt): |
| 50 | BaseModel.__init__(self, opt) |
| 51 | |
| 52 | # specify the training losses you want to print out. |
| 53 | # The training/test scripts will call <BaseModel.get_current_losses> |
| 54 | self.loss_names = ['D_A', 'G_A', 'NCE1', 'D_B', 'G_B', 'NCE2', 'G'] |
| 55 | visual_names_A = ['real_A', 'fake_B'] |
| 56 | visual_names_B = ['real_B', 'fake_A'] |
| 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 += ['idt_B', 'idt_A'] |
| 61 | visual_names_A.append('idt_B') |
| 62 | visual_names_B.append('idt_A') |
| 63 | |
| 64 | self.visual_names = visual_names_A + visual_names_B # combine visualizations for A and B |
| 65 | |
| 66 | if self.isTrain: |
| 67 | self.model_names = ['G_A', 'F1', 'D_A', 'G_B', 'F2', 'D_B'] |
nothing calls this directly
no outgoing calls
no test coverage detected