Esempio n. 1
0
def build_LOOCV(x, y, dest, leave_out_id=0):
    def load_labels():
        def load_names_from_file(file):
            with open(file) as f:
                name_list = [x.split(".")[0] for x in f]
                parsed_names = list()
                for name in name_list:
                    parsed_names.append([int(x) for x in name.split('_')[:3]])

                return parsed_names

        names = list()
        for i in range(3):
            f = load_names_from_file("{0}/3DMAD_week{1}.txt".format(
                dest, i + 1))
            names += f

        return names

    labels = load_labels()
    train_x, train_y = None, None
    test_x, test_y = None, None
    for i in range(len(x)):
        if labels[i][0] == leave_out_id:
            if test_x is None:
                test_x = np.array([x[i]])
                test_y = np.array([y[i]])
            else:
                test_x = np.append(test_x, np.array([x[i]]), axis=0)
                test_y = np.append(test_y, np.array([y[i]]), axis=0)
        else:
            if train_x is None:
                train_x = np.array([x[i]])
                train_y = np.array([y[i]])
            else:
                train_x = np.append(train_x, np.array([x[i]]), axis=0)
                train_y = np.append(train_y, np.array([y[i]]), axis=0)

    train_rppg_x = get_rppg_data(train_x, frame_rate=30)
    test_rppg_x = get_rppg_data(test_x, frame_rate=30)

    np.save("{0}/3DMAD_train_rppg_x.npy".format(dest), train_rppg_x)
    np.save("{0}/3DMAD_test_rppg_x.npy".format(dest), test_rppg_x)

    np.save("{0}/3DMAD_train_x.npy".format(dest), train_x)
    np.save("{0}/3DMAD_test_x.npy".format(dest), test_x)

    np.save("{0}/3DMAD_train_y.npy".format(dest), train_y)
    np.save("{0}/3DMAD_test_y.npy".format(dest), test_y)
def slice_partition(name, size, stride, prefix='rad'):
	from utils.loaders import get_rppg_data

	split_fake = np.load("{0}/rad_{1}_fake.npy".format(args.dest, name))
	split_real = np.load("{0}/rad_{1}_real.npy".format(args.dest, name))
	
	# slice_split_fake = slice_and_stride(split_fake, size, stride)
	# slice_split_real = slice_and_stride(split_real, size, stride)

	split_real = split_real[:, :size]
	split_fake = split_fake[:, :size]

	split = np.append(split_fake, split_real, axis=0)
	
	labels_split_fake = np.zeros([len(split_fake)])
	labels_split_real = np.ones([len(split_real)])
	
	labels = np.append(labels_split_fake, labels_split_real)

	split_rppg = get_rppg_data(split, frame_rate=24)

	# def norm_0_1(data):
	# 	return (data - data.min()) / (data.max() - data.min())

	# first_roi, second_roi = split_rppg[:, :, 0], split_rppg[:, :, 1]
	# split_rppg = ((first_roi - second_roi) ** 2).reshape(first_roi.shape[0], first_roi.shape[1], 1)
	# split_rppg = norm_0_1(split_rppg) * 255.0

	# first_rgb, second_rgb = split[:, :, :3], split[:, :, 3:]
	# split = ((first_rgb - second_rgb) ** 2).reshape(first_rgb.shape[0], first_rgb.shape[1], 3)
	# split = norm_0_1(split) * 255.0

	np.save("{0}/{1}_{2}_ppg.npy".format(args.dest, prefix, name), split_rppg)
	np.save("{0}/{1}_{2}_y.npy".format(args.dest, prefix, name), labels)
	np.save("{0}/{1}_{2}_x.npy".format(args.dest, prefix, name), split)
Esempio n. 3
0
		def load_all_data(split):
			hints = get_hints('{0}/oulu_{1}_names.txt'.format(args.dest, split))
			x = np.load('{0}/oulu_{1}_full.npy'.format(args.dest, split))[:, :120]
			y = np.zeros(len(x))

			for i in range(len(x)):
				y[i] = 1 if hints[i][3] == 1 else 0

			rppg = get_rppg_data(x, frame_rate=frame_rate)

			np.save('{0}/oulu_{1}_rppg_x.npy'.format(args.dest, split), rppg)
			np.save('{0}/oulu_{1}_x.npy'.format(args.dest, split), x)
			np.save('{0}/oulu_{1}_y.npy'.format(args.dest, split), y)

			print(rppg.shape)
Esempio n. 4
0
		def load_by_session(split, sessions):
			hints = get_hints('{0}/oulu_{1}_names.txt'.format(args.dest, split))
			x = np.load('{0}/oulu_{1}_full.npy'.format(args.dest, split))
			session_x, session_y = list(), list()
			for i in range(len(x)):
				if hints[i][1] in sessions:
					label = 1 if (hints[i][3] == 1) else 0
					session_x.append(x[i])
					session_y.append(label)
			
			session_x, session_y = np.array(session_x), np.array(session_y)

			split_rppg_x = get_rppg_data(session_x, frame_rate=frame_rate)

			np.save('{0}/oulu_{1}_x.npy'.format(args.dest, split), session_x)
			np.save('{0}/oulu_{1}_y.npy'.format(args.dest, split), session_y)
			np.save('{0}/oulu_{1}_rppg_x.npy'.format(args.dest, split), split_rppg_x)

			print(session_x.shape)
Esempio n. 5
0
		def load_by_medium(split, medium):
			hints = get_hints('{0}/oulu_{1}_names.txt'.format(args.dest, split))
			x = np.load('{0}/oulu_{1}_full.npy'.format(args.dest, split))
			medium_x, medium_y = list(), list()
			for i in range(len(x)):
				label = 1 if (hints[i][3] == 1) else 0
				if label == 1 or (((hints[i][3] - 1) % 2) == (medium % 2)):
					medium_x.append(x[i])
					medium_y.append(label)
			
			medium_x, medium_y = np.array(medium_x), np.array(medium_y)

			split_rppg_x = get_rppg_data(medium_x, frame_rate=frame_rate)

			np.save('{0}/oulu_{1}_x.npy'.format(args.dest, split), medium_x)
			np.save('{0}/oulu_{1}_y.npy'.format(args.dest, split), medium_y)
			np.save('{0}/oulu_{1}_rppg_x.npy'.format(args.dest, split), split_rppg_x)

			print(medium_x.shape)
Esempio n. 6
0
		def load_final_protocol(split, sessions, medium, phone_list):
			hints = get_hints('{0}/oulu_{1}_names.txt'.format(args.dest, split))
			x = np.load('{0}/oulu_{1}_full.npy'.format(args.dest, split))
			
			data_x, data_y = list(), list()
			for i in range(len(x)):
				if hints[i][1] not in sessions:
					continue

				label = 1 if (hints[i][3] == 1) else 0
				if (hints[i][0] in phone_list) and (label == 1 or ((hints[i][3] - 1) % 2) == (medium % 2)):
					data_x.append(x[i])
					data_y.append(label)
			
			data_x, data_y = np.array(data_x), np.array(data_y)

			split_rppg_x = get_rppg_data(data_x, frame_rate=frame_rate)

			np.save('{0}/oulu_{1}_x.npy'.format(args.dest, split), data_x)
			np.save('{0}/oulu_{1}_y.npy'.format(args.dest, split), data_y)
			np.save('{0}/oulu_{1}_rppg_x.npy'.format(args.dest, split), split_rppg_x)

			print(data_x.shape)
Esempio n. 7
0
                        x = data[i][:video_size]
                        y = 1 if hints[i][2] == 1 else 0

                        if part_x is None:
                            part_x = np.array([x])
                            part_y = list([y])
                        else:
                            part_x = np.append(part_x, np.array([x]), axis=0)
                            part_y.append(y)

            print(part_x.shape)
            return part_x, np.array(part_y)

        train_x, train_y = load_third_protocol('train')
        test_x, test_y = load_third_protocol('test')

        np.save('{0}/siw_train_x.npy'.format(args.dest), np.array(train_x))
        np.save('{0}/siw_test_x.npy'.format(args.dest), np.array(test_x))

        np.save('{0}/siw_train_y.npy'.format(args.dest), np.array(train_y))
        np.save('{0}/siw_test_y.npy'.format(args.dest), np.array(test_y))

    train_x = np.load('{0}/siw_train_x.npy'.format(args.dest))
    test_x = np.load('{0}/siw_test_x.npy'.format(args.dest))

    rppg_train_x = get_rppg_data(train_x, frame_rate=frame_rate)
    rppg_test_x = get_rppg_data(test_x, frame_rate=frame_rate)

    np.save('{0}/siw_train_rppg_x.npy'.format(args.dest), rppg_train_x)
    np.save('{0}/siw_test_rppg_x.npy'.format(args.dest), rppg_test_x)
Esempio n. 8
0
    np.save("{0}/3DMAD_train_x.npy".format(dest), train_x)
    np.save("{0}/3DMAD_test_x.npy".format(dest), test_x)

    np.save("{0}/3DMAD_train_y.npy".format(dest), train_y)
    np.save("{0}/3DMAD_test_y.npy".format(dest), test_y)


if __name__ == "__main__":
    args = get_args()
    frame_rate = 30
    video_size = frame_rate * args.time
    if '3DMAD_week1.npy' not in os.listdir(args.dest):
        Loader3DMAD.load_and_store(args.source, args.dest)

    week1 = np.load("{0}/3DMAD_week1.npy".format(args.dest))
    week2 = np.load("{0}/3DMAD_week2.npy".format(args.dest))
    week3 = np.load("{0}/3DMAD_week3.npy".format(args.dest))

    train_x = week1
    train_x = np.append(train_x, week2, axis=0)
    train_x = np.append(train_x, week3, axis=0)

    train_y = np.append(np.ones(len(week1) + len(week2)), np.zeros(len(week3)))
    # build_LOOCV(train_x, train_y, args.dest, args.id)
    x = get_rppg_data(train_x, frame_rate=30)

    np.save('./data/3DMAD_rppg_x.npy', x)
    np.save('./data/3DMAD_y.npy', train_y)
    # slice_partition('train', video_size, 1)
    # slice_partition('devel', video_size, 1)
    # slice_partition('test', video_size, 1)