def __getitem__(self, index):
     # this is what ImageFolder normally returns
     original_tuple = super(ImageFolderWithAges, self).__getitem__(index)
     age = path2age(self.imgs[index][0], self.pat, self.pos)
     # make a new tuple that includes original and the path
     tuple_with_path = (original_tuple + (age, ))
     return tuple_with_path
Example #2
0
 def __getitem__(self, index):
     # this is what ImageFolder normally returns 
     original_tuple = super(ImageFolderWithAgeGroup, self).__getitem__(index)
     img = self.transforms_(image=np.array(original_tuple[0]))["image"]
     age = path2age(self.imgs[index][0], self.pat, self.pos)
     # make a new tuple that includes original and the path
     tuple_with_path = (img, original_tuple[1], self.find_group(age))
     return tuple_with_path
def main():
    dataset = mixture
    model = DAL_model('cosface', dataset['n_cls'])
    if len(sys.argv) >= 4:
        model.load_state_dict(torch.load(sys.argv[3]))
        print(f'Loaded weights: {sys.argv[3]}')
        start_epoch = path2age(sys.argv[3], '_|\.', 0) + 1
    else:
        start_epoch = 0
    trainer = Trainer(model, dataset, int(sys.argv[1]), print_freq=1)
    save = '/data/fuzhuolin/DAL/state_dicts/1'
    trainer.train(int(sys.argv[2]), start_epoch, save)
Example #4
0
def main():
    dataset = mixture
    model = DAL_model('cosface', dataset['n_cls'])
    if len(sys.argv) >= 4:
        model.load_state_dict(torch.load(sys.argv[3]))
        print(f'Loaded weights: {sys.argv[3]}')
        start_epoch = path2age(sys.argv[3], '_|\.', 0) + 1
    else:
        start_epoch = 0
    trainer = Trainer(model, dataset, int(sys.argv[1]), print_freq=1)
    save = 'E:/2021WIN/SI681/Decorrelated-Adversarial-Learning/state_dicts/1'
    trainer.train(int(sys.argv[2]), start_epoch, save)
Example #5
0
def main():
    dataset = cacd
    model = DAL_model('cosface', dataset['n_cls'])
    model.load_state_dict(torch.load("../cache/dal-pretrained-1st-stage.pth"))
    # return
    if len(sys.argv) >= 4:
        model.load_state_dict(torch.load(sys.argv[3]))
        print(f'Loaded weights: {sys.argv[3]}')
        start_epoch = path2age(sys.argv[3], '_|\.', 0) + 1
    else:
        start_epoch = 0
    trainer = Trainer(model,
                      dataset,
                      int(sys.argv[1]),
                      print_freq=100,
                      train_head_only=False)
    save = '../cache/model_cache/'
    trainer.train(int(sys.argv[2]), start_epoch, save)