def run(self):
        if (self.RUN_READER):
            read = Reader()
            read.execute(self.BASE_PATH, self.READER_TYPES, self.BASE_SUBJECTS)

        if (self.RUN_EXTRACTOR):
            extract = Extractor()
            extract.execute(self.BASE_PATH, self.BASE_WINDOW,
                            self.WINDOW_OVERLAP, self.BASE_SUBJECTS)

        if (self.RUN_SELECTOR):
            selection_results = {}
            select = Selector()
            for st in self.SELECTOR_SELECTION_TYPE:
                for sig in self.SELECTOR_SIGNALS:
                    selection_results[sig] = []
                    selection_results[sig] = select.execute(
                        self.BASE_PATH, sig, self.BASE_SUBJECTS,
                        self.BASE_WINDOW, self.WINDOW_OVERLAP, st,
                        self.SELECTOR_ALL_SIGNS)
                    if (self.SELECTOR_ALL_SIGNS):
                        break
                print('Results = ', st)
                print('RATIO, STD')
                print(selection_results)

        if (self.RUN_CLASSIFIER):
            # self.one_classifier_and_decision('lda', 8)
            # self.one_classifier_and_decision('', 9)
            self.individual('ecg', 'pca', 1)
            # self.individual('ecg', 'lda', 2)
            # self.individual('ecg', '', 3)
            self.individual('eda', 'pca', 1)
            # self.individual('eda', 'lda', 2)
            # self.individual('eda', '', 3)
            # self.individual('emg', 'pca', 1)
            # self.individual('emg', 'lda', 2)
            # self.individual('emg', '', 3)
            self.individual('resp', 'pca', 1)
            # self.individual('resp', 'lda', 2)
            # self.individual('resp', '', 3)
            self.todos('pca', 4)
            # self.todos('lda', 5)
            # self.todos('', 6)

            self.one_classifier_and_decision('pca', 7)
Esempio n. 2
0
    def execute(self):
        """ To make feature map correctly, add self.padding_size_in_model."""
        padded_image_patch_size = self.image_patch_size + self.padding_size_in_model * 2
        dummy = sitk.Image(self.image.GetSize(), sitk.sitkUInt8)
        """ Make patch. """
        etr = Extractor(image=self.image,
                        label=dummy,
                        image_patch_size=padded_image_patch_size,
                        label_patch_size=self.label_patch_size,
                        mask=self.mask)

        etr.execute()
        image_array_list, _ = etr.output(kind="Array")

        is_cuda = torch.cuda.is_available() and True
        device = torch.device("cuda" if is_cuda else "cpu")
        """ Make feature maps. """
        self.feature_map_list = []
        with tqdm(total=len(image_array_list),
                  desc="Making feature maps..",
                  ncols=60) as pbar:
            for image_array in image_array_list:
                image_array = torch.from_numpy(image_array)[
                    None, None, ...].to(device, dtype=torch.float)

                feature_map = self.model.forwardWithoutSegmentation(
                    image_array)
                feature_map = feature_map.to("cpu").detach().numpy().astype(
                    np.float)
                feature_map = np.squeeze(feature_map)

                lower_crop_size = [0] + self.padding_size_in_model.tolist()
                upper_crop_size = [0] + self.padding_size_in_model.tolist()
                feature_map = croppingForNumpy(feature_map, lower_crop_size,
                                               upper_crop_size)
                self.feature_map_list.append(feature_map)

                pbar.update(1)
Esempio n. 3
0
    def execute(self):
        predicted_array_list = self.makeFeatureMap()

        label = sitk.Image(self.image.GetSize(), sitk.sitkUInt8)

        for ch in range(self.num_channel):
            etr = Extractor(
                    image = predicted_array_list[ch],
                    label = label,
                    mask = self.mask,
                    image_patch_size = self.image_patch_size,
                    label_patch_size = self.label_patch_size
                    )

            etr.execute()

            predicted_array_list[ch], _ = etr.output(kind="Array")

        predicted_array_list = np.array(predicted_array_list)

        num_len = predicted_array_list.shape[1]
        self.feature_map_list= []
        for l in range(num_len):
            self.feature_map_list.append(predicted_array_list[:, l, ...])
    def execute(self, base_path, window, window_overlap, subjects):
        self.window_overlap = window_overlap
        self.window = window
        self.calc_registers()

        for i in subjects:
            subject = 'S' + str(i)
            print('iniciando sujeito = ', subject)
            self.path = base_path + subject + '/data/'
            os.chdir(self.path)

            labels700 = np.loadtxt('chest_labels_filtered.txt')

            self.process(labels700, 'chest', 'ecg', self.registers700)
            self.process(labels700, 'chest', 'emg', self.registers700)
            self.process(labels700, 'chest', 'eda', self.registers700)
            self.process(labels700, 'chest', 'resp', self.registers700)


from extractor import Extractor

if __name__ == '__main__':
    window = 30
    window_overlap = True
    path = '/Volumes/My Passport/TCC/WESAD/'
    subjects = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17]
    extract = Extractor()
    extract.execute(path, window, window_overlap, subjects)

#%%