def get_list_dataset(pair_type): ele_list = dataset[pair_type][:len(dataset[pair_type]) // batch_size * batch_size] def load(idx): o = { 'input': np.stack((dataset['patches'][v].astype(np.float32) - dataset['mean'][v]) / 256.0 for v in idx), 'target': 1 if pair_type == 'matches' else -1 } o['input'] = torch.from_numpy(o['input']) o['target'] = torch.LongTensor([o['target']]) o['input'] = o['input'].float() o['target'] = o['target'].float() o['input'] = o['input'].cuda() o['target'] = o['target'].cuda() return o ele_list = list(map(load, ele_list)) ds = ListDataset(elem_list=ele_list) # ds = ds.transform({'input': torch.from_numpy, 'target': lambda x: torch.LongTensor([x])}) # ds = ds.transform({'input': torch.from_numpy, 'target': lambda x: torch.Cudaha([x])}) return ds.batch(policy='include-last', batchsize=batch_size // 2)
def get_list_dataset(pair_type): ds = ListDataset(elem_list=dataset[pair_type], load=lambda idx: {'input': np.stack((dataset['patches'][v].astype(np.float32) - dataset['mean'][v]) / 256.0 for v in idx), 'target': 1 if pair_type == 'matches' else -1}) ds = ds.transform({'input': torch.from_numpy, 'target': lambda x: torch.LongTensor([x])}) return ds.batch(policy='include-last', batchsize=batch_size // 2)
def get_list_dataset(pair_type): ds = ListDataset(elem_list=dataset[pair_type], load=lambda idx: { 'input': np.stack((dataset['patches'][v].astype(np.float32) - dataset['mean'][v]) / 256.0 for v in idx), 'target': 1 if pair_type == 'matches' else -1 }) ds = ds.transform({ 'input': torch.from_numpy, 'target': lambda x: torch.LongTensor([x]) }) return ds.batch(policy='include-last', batchsize=batch_size // 2)