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

Method __init__

models/template_model.py:41–70  ·  view source on GitHub ↗

Initialize this model class. Parameters: opt -- training/test options A few things can be done here. - (required) call the initialization function of BaseModel - define loss function, visualization images, model names, and optimizers

(self, opt)

Source from the content-addressed store, hash-verified

39 return parser
40
41 def __init__(self, opt):
42 """Initialize this model class.
43
44 Parameters:
45 opt -- training/test options
46
47 A few things can be done here.
48 - (required) call the initialization function of BaseModel
49 - define loss function, visualization images, model names, and optimizers
50 """
51 BaseModel.__init__(self, opt) # call the initialization method of BaseModel
52 # specify the training losses you want to print out. The program will call base_model.get_current_losses to plot the losses to the console and save them to the disk.
53 self.loss_names = ['loss_G']
54 # specify the images you want to save and display. The program will call base_model.get_current_visuals to save and display these images.
55 self.visual_names = ['data_A', 'data_B', 'output']
56 # specify the models you want to save to the disk. The program will call base_model.save_networks and base_model.load_networks to save and load networks.
57 # you can use opt.isTrain to specify different behaviors for training and test. For example, some networks will not be used during test, and you don't need to load them.
58 self.model_names = ['G']
59 # define networks; you can use opt.isTrain to specify different behaviors for training and test.
60 self.netG = networks.define_G(opt.input_nc, opt.output_nc, opt.ngf, opt.netG, gpu_ids=self.gpu_ids)
61 if self.isTrain: # only defined during training time
62 # define your loss functions. You can use losses provided by torch.nn such as torch.nn.L1Loss.
63 # We also provide a GANLoss class "networks.GANLoss". self.criterionGAN = networks.GANLoss().to(self.device)
64 self.criterionLoss = torch.nn.L1Loss()
65 # define and initialize optimizers. You can define one optimizer for each network.
66 # If two networks are updated at the same time, you can use itertools.chain to group them. See cycle_gan_model.py for an example.
67 self.optimizer = torch.optim.Adam(self.netG.parameters(), lr=opt.lr, betas=(opt.beta1, 0.999))
68 self.optimizers = [self.optimizer]
69
70 # Our program will automatically call <model.setup> to define schedulers, load networks, and print networks
71
72 def set_input(self, input):
73 """Unpack input data from the dataloader and perform necessary pre-processing steps.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected