Exemple #1
0
 def __init__(self,
              arch,
              normalization='batch',
              activation='leakyrelu-0.2',
              padding='same',
              pooling='avg',
              input_size=(128, 128),
              layout_dim=0,
              args=None):
     super(PatchDiscriminator, self).__init__()
     print(
         "i2g2i.combine_sg2im_neural_motifs.discriminator.PatchDiscriminator"
     )
     input_dim = 3 + layout_dim
     arch = 'I%d,%s' % (input_dim, arch)
     cnn_kwargs = {
         'arch': arch,
         'normalization': normalization,
         'activation': activation,
         'pooling': pooling,
         'padding': padding,
     }
     self.down_to_1channel = args.down_to_1channel
     self.cnn, output_dim = build_cnn(**cnn_kwargs)
     self.classifier = nn.Conv2d(output_dim, 1, kernel_size=1, stride=1)
Exemple #2
0
    def __init__(self,
                 vocab,
                 arch,
                 normalization='none',
                 activation='relu',
                 padding='same',
                 pooling='avg',
                 args=None):
        super(AcDiscriminator, self).__init__()
        print(
            "i2g2i.combine_sg2im_neural_motifs.discriminator.AcDiscriminator")
        self.vocab = vocab

        cnn_kwargs = {
            'arch': arch,
            'normalization': normalization,
            'activation': activation,
            'pooling': pooling,
            'padding': padding,
        }
        cnn, D = build_cnn(**cnn_kwargs)
        self.reconstruct_frature = args.d_obj_rec_feat_weight > 0

        if self.reconstruct_frature:
            self.cnn = cnn
            self.feature = nn.Sequential(GlobalAvgPool(), nn.Linear(D, 1024))
            self.rec_feature = nn.Sequential(GlobalAvgPool(),
                                             nn.Linear(D, 4096))
        else:
            self.cnn = nn.Sequential(cnn, GlobalAvgPool(), nn.Linear(D, 1024))

        num_objects = len(vocab['object_idx_to_name']) - 1
        self.real_classifier = nn.Linear(1024, 1)
        self.obj_classifier = nn.Linear(1024, num_objects)
Exemple #3
0
 def __init__(self,
              arch,
              normalization='batch',
              activation='leakyrelu-0.2',
              padding='same',
              pooling='avg',
              args=None):
     super(ImageEncoder, self).__init__()
     print("i2g2i.combine_sg2im_neural_motifs.encoder.ImageEncoder")
     input_dim = 3
     arch = 'I%d,%s' % (input_dim, arch)
     cnn_kwargs = {
         'arch': arch,
         'normalization': normalization,
         'activation': activation,
         'pooling': pooling,
         'padding': padding,
     }
     self.layout_noise_dim = args.layout_noise_dim
     self.object_noise_dim = args.object_noise_dim
     assert not (
         self.layout_noise_dim > 0 and self.object_noise_dim > 0
     ), "layout noise, object noise should not be applied at the same time"
     self.cnn, D = build_cnn(**cnn_kwargs)
     for i in range(len(self.cnn)):
         if isinstance(self.cnn[i], nn.Conv2d):
             origin_cnn = self.cnn[i]
             self.cnn[i] = nn.Conv2d(origin_cnn.in_channels,
                                     origin_cnn.out_channels,
                                     kernel_size=origin_cnn.kernel_size,
                                     stride=origin_cnn.stride,
                                     padding=1)
Exemple #4
0
 def __init__(self, arch, normalization='batch', activation='leakyrelu-0.2',
              padding='same', pooling='avg', input_size=(128,128),
              layout_dim=0):
   super(PatchDiscriminator, self).__init__()
   input_dim = 3 + layout_dim
   arch = 'I%d,%s' % (input_dim, arch)
   cnn_kwargs = {
     'arch': arch,
     'normalization': normalization,
     'activation': activation,
     'pooling': pooling,
     'padding': padding,
   }
   self.cnn, output_dim = build_cnn(**cnn_kwargs)
   self.classifier = nn.Conv2d(output_dim, 1, kernel_size=1, stride=1)
Exemple #5
0
  def __init__(self, vocab, arch, normalization='none', activation='relu',
               padding='same', pooling='avg'):
    super(AcDiscriminator, self).__init__()
    self.vocab = vocab

    cnn_kwargs = {
      'arch': arch,
      'normalization': normalization,
      'activation': activation,
      'pooling': pooling, 
      'padding': padding,
    }
    cnn, D = build_cnn(**cnn_kwargs)
    self.cnn = nn.Sequential(cnn, GlobalAvgPool(), nn.Linear(D, 1024))
    num_objects = len(vocab['object_idx_to_name'])

    self.real_classifier = nn.Linear(1024, 1)
    self.obj_classifier = nn.Linear(1024, num_objects)
Exemple #6
0
    def __init__(self,
                 vocab,
                 arch,
                 normalization='none',
                 activation='relu',
                 padding='same',
                 vecs_size=1024,
                 pooling='avg'):
        super(AppearanceEncoder, self).__init__()
        self.vocab = vocab

        cnn_kwargs = {
            'arch': arch,
            'normalization': normalization,
            'activation': activation,
            'pooling': pooling,
            'padding': padding,
        }
        cnn, channels = build_cnn(**cnn_kwargs)
        self.cnn = nn.Sequential(cnn, GlobalAvgPool(),
                                 nn.Linear(channels, vecs_size))
Exemple #7
0
    def __init__(self,
                 arch,
                 normalization='none',
                 activation='relu',
                 padding='same',
                 pooling='avg',
                 args=None):
        super(Encoder, self).__init__()
        print("i2g2i.combine_sg2im_neural_motifs.encoder.Encoder")
        self.object_noise_dim = args.object_noise_dim

        cnn_kwargs = {
            'arch': arch,
            'normalization': normalization,
            'activation': activation,
            'pooling': pooling,
            'padding': padding,
        }
        cnn, D = build_cnn(**cnn_kwargs)
        self.cnn = nn.Sequential(cnn, GlobalAvgPool(),
                                 nn.Linear(D, self.object_noise_dim * 2))
Exemple #8
0
 def __init__(self,
              arch,
              normalization='batch',
              activation='leakyrelu-0.2',
              padding='same',
              pooling='avg',
              input_size=(128, 128),
              layout_dim=0,
              sg_context_dim=0):
     super(CondGANDiscriminator, self).__init__()
     input_dim = 3 + layout_dim + sg_context_dim
     arch = 'I%d,%s' % (input_dim, arch)
     cnn_kwargs = {
         'arch': arch,
         'normalization': normalization,
         'activation': activation,
         'pooling': pooling,
         'padding': padding,
     }
     cnn, output_dim = build_cnn(**cnn_kwargs)
     self.cnn = nn.Sequential(cnn, GlobalAvgPool(),
                              nn.Linear(output_dim, 1024))
     self.classifier = nn.Linear(1024, 1)