Ejemplo n.º 1
0
    def extract_low_level_features(self):
        """ docstring """

        start = get_time()

        np.random.seed(7)
        sd = int(np.random.rand(1, 1)[0, 0] * 1e9)
        self.n_jobs = N_JOBS

        fnames_a = self.data_a.metainfo['all_fnames']

        tasks = []
        for fname in fnames_a:
            for trial in self.llf_trials_a:
                path = 'low_level_features/{0}/{1}/{2}'.format(
                    trial["NTV"], rois_available[trial["LGF"]],
                    measures_available[trial["M"]])

                output_path = os.path.join(self.data_a.output_path, path)

                tasks += [
                    LowLevelFeatures(self.data_a.dataset_path,
                                     output_path,
                                     fname,
                                     trial["LGF"],
                                     trial["M"],
                                     n_cuboids=trial["NTV"],
                                     seed=sd)
                ]

        print "running %d tasks in parallel" % len(tasks)
        sys.stdout.flush()
        RunInParallel(tasks, self.n_jobs).run()

        fnames_b = self.data_b.metainfo['all_fnames']

        tasks = []
        for fname in fnames_b:
            for trial in self.llf_trials_b:
                path = 'low_level_features/{0}/{1}/{2}'.format(
                    trial["NTV"], rois_available[trial["LGF"]],
                    measures_available[trial["M"]])

                output_path = os.path.join(self.data_b.output_path, path)

                tasks += [
                    LowLevelFeatures(self.data_b.dataset_path,
                                     output_path,
                                     fname,
                                     trial["LGF"],
                                     trial["M"],
                                     n_cuboids=trial["NTV"],
                                     seed=sd)
                ]

        print "running %d tasks in parallel" % len(tasks)
        RunInParallel(tasks, self.n_jobs).run()

        total_time_elapsed(start, get_time())
Ejemplo n.º 2
0
    def extract_low_level_features(self):
        """ docstring """

        start = get_time()

        np.random.seed(7)

        if self.data.__class__.__name__.lower() == 'maskattack':
            fnames = self.data.metainfo['all_fnames']
        else:
            print 'This Protocol is not defined for this dataset!'
            sys.exit(0)

        tasks = []
        sd = int(np.random.rand(1, 1)[0, 0] * 1e9)
        for fname in fnames:
            for trial in self.llf_trials:
                path = 'low_level_features/{0}/{1}/{2}'.format(trial["NTV"],
                                                               rois_available[trial["LGF"]],
                                                               measures_available[trial["M"]])

                output_path = os.path.join(self.data.output_path, path)

                tasks += [LowLevelFeatures(self.data.dataset_path, output_path, fname,
                                           trial["LGF"],
                                           trial["M"],
                                           n_cuboids=trial["NTV"],
                                           frame_numbers=self.frame_numbers,
                                           seed=sd)]

        print "running %d tasks in parallel" % len(tasks)
        RunInParallel(tasks, self.n_jobs).run()

        total_time_elapsed(start, get_time())
Ejemplo n.º 3
0
    def extract_low_level_features(self):
        """ docstring """

        start = get_time()

        np.random.seed(7)

        fnames = self.data.metainfo['all_fnames']

        # if self.data.__class__.__name__.lower() == 'replayattack':
        #     # fnames = [fname for fname in self.data.metainfo['all_fnames']
        #     #                 if ('train/' in fname)or('devel/' in fname)or('test/' in fname)]
        # elif self.data.__class__.__name__.lower() == 'casia':
        #     fnames = self.data.metainfo['all_fnames']
        # elif self.data.__class__.__name__.lower() == 'maskattack':
        #     fnames = self.data.metainfo['all_fnames']
        # elif self.data.__class__.__name__.lower() == 'uvad':
        #     fnames = self.data.metainfo['all_fnames']
        #     # # search substrings
        #     # fnames_camera = fnames[np.array(["attack/nikon" in s
        #     #     for s in fnames.flat]).reshape(fnames.shape)]
        #     # fnames = [fname for fname in fnames_camera if ('monitor7' in fname)]
        # else:
        #     pass

        tasks = []
        sd = int(np.random.rand(1, 1)[0, 0] * 1e9)
        for fname in fnames:
            for trial in self.llf_trials:
                path = 'low_level_features/{0}/{1}/{2}'.format(trial["NTV"],
                                                               rois_available[trial["LGF"]],
                                                               measures_available[trial["M"]])

                output_path = os.path.join(self.data.output_path, path)

                tasks += [LowLevelFeatures(self.data.dataset_path, output_path, fname,
                                           trial["LGF"],
                                           trial["M"],
                                           n_cuboids=trial["NTV"],
                                           only_face=self.only_face,
                                           frame_numbers=self.frame_numbers,
                                           seed=sd,
                                           get_faceloc=self.data.get_faceloc)]

        if self.n_jobs > 1:
            print "running %d tasks in parallel" % len(tasks)
            RunInParallel(tasks, self.n_jobs).run()
        else:
            print "running %d tasks in sequence" % len(tasks)
            for idx in range(len(fnames)):
                tasks[idx].run()
                progressbar('-- RunInSequence', idx, len(fnames))

        elapsed = total_time_elapsed(start, get_time())
        print 'spent time: {0}!'.format(elapsed)
        sys.stdout.flush()
Ejemplo n.º 4
0
    def extract_low_level_features(self):
        """ docstring """

        start = get_time()

        np.random.seed(7)

        fnames = []

        if self.data.__class__.__name__.lower() == 'replayattack':

            fnames = self.data.metainfo['all_fnames']
            fnames = [
                fname for fname in fnames if (self.sample in fname) and (
                    ('hand/' in fname) or ('real' in fname))
            ]

        elif self.data.__class__.__name__.lower() == 'casia':
            fnames = self.data.metainfo['all_fnames']

        elif self.data.__class__.__name__.lower() == 'maskattack':
            fnames = self.data.metainfo['all_fnames']

        elif self.data.__class__.__name__.lower() == 'uvad':
            fnames = self.data.metainfo['all_fnames']

        else:
            pass

        for realization in [1]:
            sd = int(np.random.rand(1, 1)[0, 0] * 1e9)
            for fname in fnames:
                for trial in self.llf_trials:
                    path = 'realization_{0}/low_level_features/{1}/{2}/{3}'.format(
                        realization, trial["NTV"],
                        rois_available[trial["LGF"]],
                        measures_available[trial["M"]])

                    output_path = os.path.join(self.data.output_path, path)

                    LowLevelFeatures(self.data.dataset_path,
                                     output_path,
                                     fname,
                                     trial["LGF"],
                                     trial["M"],
                                     n_cuboids=trial["NTV"],
                                     analize=True,
                                     frame_numbers=10,
                                     seed=sd).analize_one_sample()

        total_time_elapsed(start, get_time())
Ejemplo n.º 5
0
    def extract_low_level_features(self):
        """ docstring """

        start = get_time()

        np.random.seed(7)

        fnames = self.data.metainfo['all_fnames']

        tasks = []
        sd = int(np.random.rand(1, 1)[0, 0] * 1e9)
        for fname in fnames:
            for trial in self.llf_trials:
                path = 'low_level_features/{0}/{1}/{2}'.format(
                    trial["NTV"], rois_available[trial["LGF"]],
                    measures_available[trial["M"]])

                output_path = os.path.join(self.data.output_path, path)

                tasks += [
                    LowLevelFeatures(self.data.dataset_path,
                                     output_path,
                                     fname,
                                     trial["LGF"],
                                     trial["M"],
                                     n_cuboids=trial["NTV"],
                                     only_face=self.only_face,
                                     frame_numbers=self.frame_numbers,
                                     seed=sd,
                                     get_faceloc=self.data.get_faceloc)
                ]

        if self.n_jobs > 1:
            print "running %d tasks in parallel" % len(tasks)
            RunInParallel(tasks, self.n_jobs).run()
        else:
            print "running %d tasks in sequence" % len(tasks)
            for idx in range(len(fnames)):
                tasks[idx].run()
                progressbar('-- RunInSequence', idx, len(fnames))

        elapsed = total_time_elapsed(start, get_time())
        print 'spent time: {0}!'.format(elapsed)
        sys.stdout.flush()
Ejemplo n.º 6
0
    def extract_low_level_features(self):
        """ docstring """

        start = get_time()

        np.random.seed(7)

        seeds = []
        for _ in self.realizations:
            seeds += [int(np.random.rand(1, 1)[0, 0] * 1e9)]

        fnames = self.data.metainfo['all_fnames']

        tasks = []
        for realization, sd in zip(self.realizations, seeds):
            print "realization, sd", realization, sd
            for fname in fnames:
                for trial in self.llf_trials:
                    path = 'realization_{0}/low_level_features/{1}/{2}/{3}'.format(
                        realization, trial["NTV"],
                        rois_available[trial["LGF"]],
                        measures_available[trial["M"]])

                    output_path = os.path.join(self.data.output_path, path)

                    tasks += [
                        LowLevelFeatures(self.data.dataset_path,
                                         output_path,
                                         fname,
                                         trial["LGF"],
                                         trial["M"],
                                         n_cuboids=trial["NTV"],
                                         seed=sd)
                    ]

        print "running %d tasks in parallel" % len(tasks)
        RunInParallel(tasks, self.n_jobs).run()

        total_time_elapsed(start, get_time())
Ejemplo n.º 7
0
    def extract_low_level_features(self):

        start = get_time()

        np.random.seed(7)
        sd = int(np.random.rand(1, 1)[0, 0] * 1e9)
        self.n_jobs = N_JOBS

        # if self.data_a.__class__.__name__.lower() == 'replayattack':
        #     # fnames = [fname for fname in self.data_a.metainfo['all_fnames']
        #     #                 if ('train/' in fname)or('devel/' in fname)or('test/' in fname)]
        #     fnames_a = self.data_a.metainfo['all_fnames']
        # elif self.data_a.__class__.__name__.lower() == 'casia':
        #     fnames = self.data_a.metainfo['all_fnames']
        # elif self.data_a.__class__.__name__.lower() == 'maskattack':
        #     fnames = self.data_a.metainfo['all_fnames']
        # elif self.data_a.__class__.__name__.lower() == 'uvad':
        #     fnames = self.data_a.metainfo['all_fnames']
        #     # # search substrings
        #     # fnames_camera = fnames[np.array(["attack/nikon" in s
        #     #     for s in fnames.flat]).reshape(fnames.shape)]
        #     # fnames = [fname for fname in fnames_camera if ('monitor7' in fname)]
        # else:
        #     pass

        # if self.data_b.__class__.__name__.lower() == 'replayattack':
        #     # fnames = [fname for fname in self.data_b.metainfo['all_fnames']
        #     #                 if ('train/' in fname)or('devel/' in fname)or('test/' in fname)]
        #     fnames_a = self.data_b.metainfo['all_fnames']
        # elif self.data_b.__class__.__name__.lower() == 'casia':
        #     fnames = self.data_b.metainfo['all_fnames']
        # elif self.data_b.__class__.__name__.lower() == 'maskattack':
        #     fnames = self.data_b.metainfo['all_fnames']
        # elif self.data_b.__class__.__name__.lower() == 'uvad':
        #     fnames = self.data_b.metainfo['all_fnames']
        #     # # search substrings
        #     # fnames_camera = fnames[np.array(["attack/nikon" in s
        #     #     for s in fnames.flat]).reshape(fnames.shape)]
        #     # fnames = [fname for fname in fnames_camera if ('monitor7' in fname)]
        # else:
        #     pass

        fnames_a = self.data_a.metainfo['all_fnames']

        tasks = []
        for fname in fnames_a:
            for trial in self.llf_trials_a:
                path = 'low_level_features/{0}/{1}/{2}'.format(
                    trial["NTV"], rois_available[trial["LGF"]],
                    measures_available[trial["M"]])

                output_path = os.path.join(self.data_a.output_path, path)

                tasks += [
                    LowLevelFeatures(
                        self.data_a.dataset_path,
                        output_path,
                        fname,
                        trial["LGF"],
                        trial["M"],
                        n_cuboids=trial["NTV"],
                        seed=sd,
                    )
                ]

        print "running %d tasks in parallel" % len(tasks)
        sys.stdout.flush()
        RunInParallel(tasks, self.n_jobs).run()

        fnames_b = self.data_b.metainfo['all_fnames']

        tasks = []
        for fname in fnames_b:
            for trial in self.llf_trials_b:
                path = 'low_level_features/{0}/{1}/{2}'.format(
                    trial["NTV"], rois_available[trial["LGF"]],
                    measures_available[trial["M"]])

                output_path = os.path.join(self.data_b.output_path, path)

                tasks += [
                    LowLevelFeatures(self.data_b.dataset_path,
                                     output_path,
                                     fname,
                                     trial["LGF"],
                                     trial["M"],
                                     n_cuboids=trial["NTV"],
                                     seed=sd)
                ]

        print "running %d tasks in parallel" % len(tasks)
        RunInParallel(tasks, self.n_jobs).run()

        total_time_elapsed(start, get_time())