Пример #1
0
  def init_network(self, opt):
    Base_Model.init_network(self, opt)

    self.if_pool = opt.if_pool
    self.multi_view = opt.multi_view
    self.conditional_D = opt.conditional_D
    assert len(self.multi_view) > 0

    self.loss_names = ['D', 'G']
    self.metrics_names = ['Mse', 'CosineSimilarity', 'PSNR']
    self.visual_names = ['G_real', 'G_fake', 'G_input', 'G_Map_fake_F', 'G_Map_real_F', 'G_Map_fake_S', 'G_Map_real_S']

    # identity loss
    if self.opt.idt_lambda > 0:
      self.loss_names += ['idt']

    # feature metric loss
    if self.opt.fea_m_lambda > 0:
      self.loss_names += ['fea_m']

    # map loss
    if self.opt.map_m_lambda > 0:
      self.loss_names += ['map_m']

    if self.training:
      self.model_names = ['G', 'D']
    else:  # during test time, only load Gs
      self.model_names = ['G']

    self.netG = factory.define_3DG(opt.noise_len, opt.input_shape, opt.output_shape,
                                   opt.input_nc_G, opt.output_nc_G, opt.ngf, opt.which_model_netG,
                                   opt.n_downsampling, opt.norm_G, not opt.no_dropout,
                                   opt.init_type, self.gpu_ids, opt.n_blocks,
                                   opt.encoder_input_shape, opt.encoder_input_nc, opt.encoder_norm,
                                   opt.encoder_blocks, opt.skip_number, opt.activation_type, opt=opt)

    if self.training:
      if opt.ganloss == 'gan':
        use_sigmoid = True
      elif opt.ganloss == 'lsgan':
        use_sigmoid = False
      else:
        raise ValueError()

      # conditional Discriminator
      if self.conditional_D:
        d_input_channels = opt.input_nc_D + 1
      else:
        d_input_channels = opt.input_nc_D
      self.netD = factory.define_D(d_input_channels, opt.ndf,
                                   opt.which_model_netD,
                                   opt.n_layers_D, opt.norm_D,
                                   use_sigmoid, opt.init_type, self.gpu_ids,
                                   opt.discriminator_feature, num_D=opt.num_D, n_out_channels=opt.n_out_ChannelsD)
      if self.if_pool:
        self.fake_pool = ImagePool(opt.pool_size)
Пример #2
0
    def init_network(self, opt):
        Base_Model.init_network(self, opt)

        self.loss_names = ['D', 'G']
        self.metrics_names = ['Mse', 'CosineSimilarity']
        self.visual_names = [
            'G_real', 'G_fake', 'G_input', 'G_map_fake', 'G_map_real'
        ]

        # identity loss
        if self.opt.idt_lambda > 0:
            self.loss_names += ['idt']

        # feature metric loss
        if self.opt.fea_m_lambda > 0:
            self.loss_names += ['fea_m']

        # map loss
        if self.opt.map_m_lambda > 0:
            self.loss_names += ['map_m']

        if self.training:
            self.model_names = ['G', 'D']
        else:  # during test time, only load Gs
            self.model_names = ['G']

        self.netG = factory.define_3DG(
            opt.noise_len, opt.input_shape, opt.output_shape, opt.input_nc_G,
            opt.output_nc_G, opt.ngf, opt.which_model_netG, opt.n_downsampling,
            opt.norm_G, not opt.no_dropout, opt.init_type, self.gpu_ids,
            opt.n_blocks, opt.encoder_input_shape, opt.encoder_input_nc,
            opt.encoder_norm)

        if self.training:
            if opt.ganloss == 'gan':
                use_sigmoid = True
            elif opt.ganloss == 'lsgan':
                use_sigmoid = False
            elif opt.ganloss == 'wgan':
                self.loss_names += ['wasserstein']
                use_sigmoid = False
            elif opt.ganloss == 'wgan_gp':
                self.loss_names += ['wasserstein', 'grad_penalty']
                use_sigmoid = False
            else:
                raise ValueError()

            self.netD = factory.define_D(opt.input_nc_D, opt.ndf,
                                         opt.which_model_netD, opt.n_layers_D,
                                         opt.norm_D, use_sigmoid,
                                         opt.init_type, self.gpu_ids,
                                         opt.discriminator_feature)

            self.fake_pool = ImagePool(opt.pool_size)
Пример #3
0
    def init_network(self, opt):
        Base_Model.init_network(self, opt)

        self.if_pool = opt.if_pool
        self.multi_view = opt.multi_view

        assert len(self.multi_view) > 0

        self.metrics_names = ['Mse', 'CosineSimilarity', 'PSNR']
        self.visual_names = [
            'G_real', 'G_fake', 'G_input1', 'G_input2', 'G_Map_fake_F',
            'G_Map_real_F', 'G_Map_fake_S', 'G_Map_real_S'
        ]

        self.netG = factory.define_3DG(opt.noise_len,
                                       opt.input_shape,
                                       opt.output_shape,
                                       opt.input_nc_G,
                                       opt.output_nc_G,
                                       opt.ngf,
                                       opt.which_model_netG,
                                       opt.n_downsampling,
                                       opt.norm_G,
                                       not opt.no_dropout,
                                       opt.init_type,
                                       self.gpu_ids,
                                       opt.n_blocks,
                                       opt.encoder_input_shape,
                                       opt.encoder_input_nc,
                                       opt.encoder_norm,
                                       opt.encoder_blocks,
                                       opt.skip_number,
                                       opt.activation_type,
                                       opt=opt)

        self.loss_names = ['idt']
        self.model_names = ['G']

        # map loss
        if self.opt.map_projection_lambda > 0:
            self.loss_names += ['map_m']
Пример #4
0
    def init_network(self, opt):
        Base_Model.init_network(self, opt)

        self.if_pool = opt.if_pool
        self.multi_view = opt.multi_view
        self.conditional_D = opt.conditional_D
        self.order_map_list = [(0, 1, 2, 3, 4), (0, 1, 3, 2, 4),
                               (0, 1, 4, 2, 3)]
        assert len(self.multi_view) >= 0

        self.loss_names = ['D', 'G']
        self.metrics_names = ['Mse', 'CosineSimilarity', 'PSNR']
        self.visual_names = [
            'G_real', 'G_fake', 'G_input', 'G_Map_fake_F', 'G_Map_real_F',
            'G_Map_fake_S', 'G_Map_real_S'
        ]
        self.model_names = ['G']

        if self.training:
            self.model_names += ['D']

            # identity loss
            if self.opt.idt_lambda > 0:
                self.loss_names += ['idt']

            # feature metric loss
            if self.opt.feature_D_lambda > 0:
                self.loss_names += ['fea_m']

            self.loss_names += ['D_Map', 'G_Map']

            # feature metric loss
            if self.opt.feature_D_map_lambda > 0:
                self.loss_names += ['fea_m_Map']

            # map loss
            if self.opt.map_projection_lambda > 0:
                self.loss_names += ['idt_Map']

            # models
            self.model_names += ['D_Map']

        self.netG = factory.define_3DG(opt.noise_len,
                                       opt.input_shape,
                                       opt.output_shape,
                                       opt.input_nc_G,
                                       opt.output_nc_G,
                                       opt.ngf,
                                       opt.which_model_netG,
                                       opt.n_downsampling,
                                       opt.norm_G,
                                       not opt.no_dropout,
                                       opt.init_type,
                                       self.gpu_ids,
                                       opt.n_blocks,
                                       opt.encoder_input_shape,
                                       opt.encoder_input_nc,
                                       opt.encoder_norm,
                                       opt.encoder_blocks,
                                       opt.skip_number,
                                       opt.activation_type,
                                       opt=opt)

        if self.training:
            # out of discriminator is not probability when
            # GAN loss is LSGAN
            use_sigmoid = False

            # conditional Discriminator
            if self.conditional_D:
                d_input_channels = opt.input_nc_D + 1
            else:
                d_input_channels = opt.input_nc_D
            self.netD = factory.define_D(d_input_channels,
                                         opt.ndf,
                                         opt.which_model_netD,
                                         opt.n_layers_D,
                                         opt.norm_D,
                                         use_sigmoid,
                                         opt.init_type,
                                         self.gpu_ids,
                                         opt.discriminator_feature,
                                         num_D=opt.num_D,
                                         n_out_channels=opt.n_out_ChannelsD)

            self.netD_Map = factory.define_D(
                len(self.multi_view),
                opt.map_ndf,
                opt.map_which_model_netD,
                opt.map_n_layers_D,
                opt.map_norm_D,
                use_sigmoid,
                opt.init_type,
                self.gpu_ids,
                opt.discriminator_feature,
                opt.map_num_D,
                n_out_channels=opt.map_n_out_ChannelsD)
            if self.if_pool:
                self.fake_pool = ImagePool(opt.pool_size)
                self.fake_pool_Map = ImagePool(opt.map_pool_size)