text
stringlengths 1
93.6k
|
|---|
p = random.random()
|
if p < 0.5:
|
#print('Flip')
|
new_image_x = cv2.flip(image_x, 1)
|
new_image_x_depth = cv2.flip(image_x_depth, 1)
|
new_image_x_ir = cv2.flip(image_x_ir, 1)
|
return {'image_x': new_image_x, 'image_x_depth': new_image_x_depth, 'image_x_ir': new_image_x_ir, 'spoofing_label': spoofing_label, 'map_x1': map_x1}
|
else:
|
#print('no Flip')
|
return {'image_x': image_x, 'image_x_depth': image_x_depth, 'image_x_ir': image_x_ir, 'spoofing_label': spoofing_label, 'map_x1': map_x1}
|
class ToTensor(object):
|
"""
|
Convert ndarrays in sample to Tensors.
|
process only one batch every time
|
"""
|
def __call__(self, sample):
|
image_x, image_x_depth, image_x_ir, spoofing_label, map_x1 = sample['image_x'],sample['image_x_depth'],sample['image_x_ir'],sample['spoofing_label'],sample['map_x1']
|
# swap color axis because
|
# numpy image: (batch_size) x H x W x C
|
# torch image: (batch_size) x C X H X W
|
image_x = image_x[:,:,::-1].transpose((2, 0, 1))
|
image_x = np.array(image_x)
|
image_x_depth = image_x_depth[:,:,::-1].transpose((2, 0, 1))
|
image_x_depth = np.array(image_x_depth)
|
image_x_ir = image_x_ir[:,:,::-1].transpose((2, 0, 1))
|
image_x_ir = np.array(image_x_ir)
|
map_x1 = np.array(map_x1)
|
spoofing_label_np = np.array([0],dtype=np.long)
|
spoofing_label_np[0] = spoofing_label
|
return {'image_x': torch.from_numpy(image_x.astype(np.float)).float(), 'image_x_depth': torch.from_numpy(image_x_depth.astype(np.float)).float(), 'image_x_ir': torch.from_numpy(image_x_ir.astype(np.float)).float(), 'spoofing_label': torch.from_numpy(spoofing_label_np.astype(np.long)).long(), 'map_x1': torch.from_numpy(map_x1.astype(np.float)).float()}
|
# /home/ztyu/FAS_dataset/OULU/Train_images/ 6_3_20_5_121_scene.jpg 6_3_20_5_121_scene.dat
|
# /home/ztyu/FAS_dataset/OULU/IJCB_re/OULUtrain_images/ 6_3_20_5_121_depth1D.jpg
|
class Spoofing_train(Dataset):
|
def __init__(self, info_list, root_dir, transform=None):
|
self.landmarks_frame = pd.read_csv(info_list, delimiter=' ', header=None)
|
self.root_dir = root_dir
|
self.transform = transform
|
def __len__(self):
|
return len(self.landmarks_frame)
|
def __getitem__(self, idx):
|
#print(self.landmarks_frame.iloc[idx, 0])
|
videoname = str(self.landmarks_frame.iloc[idx, 0])
|
image_path = os.path.join(self.root_dir, videoname)
|
videoname_depth = str(self.landmarks_frame.iloc[idx, 1])
|
image_path_depth = os.path.join(self.root_dir, videoname_depth)
|
videoname_ir = str(self.landmarks_frame.iloc[idx, 2])
|
image_path_ir = os.path.join(self.root_dir, videoname_ir)
|
#log_file2 = open('temp.txt', 'w')
|
#log_file2.write('%s \n' % (image_path))
|
#log_file2.write('%s \n' % (image_path_depth))
|
#log_file2.write('%s \n' % (image_path_ir))
|
#log_file2.flush()
|
image_x, map_x1 = self.get_single_image_x_RGB(image_path)
|
image_x_depth = self.get_single_image_x(image_path_depth)
|
image_x_ir = self.get_single_image_x(image_path_ir)
|
spoofing_label = self.landmarks_frame.iloc[idx, 3]
|
if spoofing_label == 1: # real
|
spoofing_label = 1 # real
|
#map_x1 = np.zeros((28, 28)) # real
|
#map_x1 = np.ones((28, 28))
|
else: # fake
|
spoofing_label = 0
|
#map_x1 = np.ones((28, 28)) # fake
|
map_x1 = np.zeros((28, 28))
|
sample = {'image_x': image_x, 'image_x_depth': image_x_depth, 'image_x_ir': image_x_ir, 'spoofing_label': spoofing_label, 'map_x1': map_x1}
|
if self.transform:
|
sample = self.transform(sample)
|
return sample
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.