Ejemplo n.º 1
0
 def __init__(self,
              data_name,
              img_dir,
              bit,
              visdom=True,
              batch_size=128,
              cuda=True,
              **kwargs):
     super(PRDH, self).__init__("PRDH", data_name, bit, batch_size, visdom,
                                cuda)
     self.train_data, self.valid_data = single_data(data_name,
                                                    img_dir,
                                                    batch_size=batch_size,
                                                    **kwargs)
     self.loss_store = [
         "inter loss", 'intra loss', 'decorrelation loss',
         'regularization loss', 'loss'
     ]
     self.parameters = {'gamma': 1, 'lambda': 1}
     self.max_epoch = 500
     self.lr = {'img': 10**(-1.5), 'txt': 10**(-1.5)}
     self.lr_decay_freq = 1
     self.lr_decay = (10**(-1.5) - 1e-6) / self.max_epoch
     self.num_train = len(self.train_data)
     self.img_model = cnnf.get_cnnf(bit)
     self.txt_model = MLP.MLP(self.train_data.get_tag_length(),
                              bit,
                              leakRelu=False)
     self.F_buffer = torch.randn(self.num_train, bit)
     self.G_buffer = torch.randn(self.num_train, bit)
     self.train_L = self.train_data.get_all_label()
     self.ones = torch.ones(batch_size, 1)
     self.ones_ = torch.ones(self.num_train - batch_size, 1)
     if cuda:
         self.img_model = self.img_model.cuda()
         self.txt_model = self.txt_model.cuda()
         self.train_L = self.train_L.cuda()
         self.F_buffer = self.F_buffer.cuda()
         self.G_buffer = self.G_buffer.cuda()
         self.ones = self.ones.cuda()
         self.ones_ = self.ones_.cuda()
     self.Sim = calc_neighbor(self.train_L, self.train_L)
     self.B = torch.sign(self.F_buffer + self.G_buffer)
     optimizer_img = SGD(self.img_model.parameters(), lr=self.lr['img'])
     optimizer_txt = SGD(self.txt_model.parameters(), lr=self.lr['txt'])
     self.optimizers = [optimizer_img, optimizer_txt]
     self._init()
Ejemplo n.º 2
0
    def __init__(self,
                 data_name: str,
                 val_freq: int,
                 img_dir: str,
                 bit: int,
                 visdom=True,
                 batch_size=128,
                 cuda=True,
                 **kwargs):
        super(CMHH, self).__init__("CMHH", data_name, bit, batch_size, visdom,
                                   cuda)
        self.train_data, self.valid_data = single_data(data_name,
                                                       img_dir,
                                                       batch_size=batch_size,
                                                       **kwargs)
        self.loss_store = ['focal loss', 'quantization loss', 'loss']
        self.parameters = {'gamma': 2, 'alpha': 0.5, 'beta': 0.5, 'lambda': 0}
        self.lr = {'img': 0.02, 'txt': 0.2}
        self.lr_decay_freq = 15
        self.lr_decay = 0.5
        self.val_freq = val_freq

        self.num_train = len(self.train_data)
        self.img_model = alexnet.get_alexnet(bit=bit)
        self.txt_model = MLP.MLP(self.train_data.get_tag_length(), bit)
        self.train_label = self.train_data.get_all_label()
        self.F_buffer = torch.randn(self.num_train, bit)
        self.G_buffer = torch.randn(self.num_train, bit)
        if cuda:
            self.img_model = self.img_model.cuda()
            self.txt_model = self.txt_model.cuda()
            self.train_label = self.train_label.cuda()
            self.F_buffer = self.F_buffer.cuda()
            self.G_buffer = self.G_buffer.cuda()
        self.B = torch.sign(self.F_buffer + self.G_buffer)

        optimizer_img = SGD(self.img_model.parameters(),
                            lr=self.lr['img'],
                            momentum=0.9)
        optimizer_txt = SGD(self.txt_model.parameters(),
                            lr=self.lr['txt'],
                            momentum=0.9)
        self.optimizers = [optimizer_img, optimizer_txt]
        self._init()
Ejemplo n.º 3
0
 def __init__(self,
              data_name: str,
              img_dir: str,
              bit: int,
              visdom=True,
              batch_size=128,
              cuda=True,
              **kwargs):
     super(CHN, self).__init__("CHN", data_name, bit, batch_size, visdom,
                               cuda)
     self.train_data, self.valid_data = single_data(data_name,
                                                    img_dir,
                                                    batch_size=batch_size,
                                                    **kwargs)
     self.loss_store = ['cosine loss', 'quantization loss', 'loss']
     self.parameters = {'beta': 0.8, 'lambda': 0.01}
     self.lr = {'img': 0.01, 'txt': 1}
     self.lr_decay_freq = 10
     self.lr_decay = 0.5
     self.num_train = len(self.train_data)
     self.img_model = cnnf.get_cnnf(bit)
     self.txt_model = MLP.MLP(self.train_data.get_tag_length(), bit)
     self.F_buffer = torch.randn(self.num_train, bit)
     self.G_buffer = torch.randn(self.num_train, bit)
     self.train_L = self.train_data.get_all_label()
     if cuda:
         self.img_model = self.img_model.cuda()
         self.txt_model = self.txt_model.cuda()
         self.train_L = self.train_L.cuda()
         self.F_buffer = self.F_buffer.cuda()
         self.G_buffer = self.G_buffer.cuda()
     optimizer_img = SGD(self.img_model.parameters(),
                         lr=self.lr['img'],
                         momentum=0.9)
     optimizer_txt = SGD(self.txt_model.parameters(),
                         lr=self.lr['txt'],
                         momentum=0.9)
     self.optimizers = [optimizer_img, optimizer_txt]
     self._init()