} #load image source_image_root = os.path.join('/1116', 'SUN', 'rgb') target_image_root = os.path.join('/1116', 'SUN', 'hha') train_list = os.path.join('/1116', 'SUN', 'train_label.txt') test_list = os.path.join('/1116', 'SUN', 'test_label.txt') #phase = 'train' # train or test data_list = {'train': train_list, 'test': test_list} domain = 'target' #source or target data_image_root = {'source': source_image_root, 'target': target_image_root} dataset = { phase: GetLoader(data_root=os.path.join(data_image_root[domain], phase), data_list=data_list[phase], transform=data_transforms[phase]) for phase in ['train', 'test'] } dataset_sizes = {phase: len(dataset[phase]) for phase in ['train', 'test']} dataloaders = { phase: torch.utils.data.DataLoader(dataset=dataset[phase], batch_size=batch_size, shuffle=False, num_workers=8) for phase in ['train', 'test'] } # Train and evaluate def train_model(model, criterion, optimizer, scheduler, num_epochs=25):
else: data_list = test_list domain = 'source' #source or target if domain == 'source': data_image_root = source_image_root feaname = 'rgb_' + phase + '_features.npy' else: data_image_root = target_image_root feaname = 'hha_' + phase + '_features.npy' model_name = 'sun_model_epoch_42.pth' print(data_list) dataset_source = GetLoader(data_root=os.path.join(data_image_root, phase), data_list=data_list, transform=data_transforms['test']) dataloader_source = torch.utils.data.DataLoader(dataset=dataset_source, batch_size=batch_size, shuffle=False, num_workers=8) data_source_iter = iter(dataloader_source) # load model model_root = os.path.join('models', model_name) my_net = torch.load(model_root) for idx, m in enumerate(my_net.named_modules()): print(idx, '-->', m) # inter_feature = {} # def make_hook(name, flag):