Ejemplo n.º 1
0
    def data_generation(self, list_files_temp):
        data_x = []
        data_y = []

        for file_name in list_files_temp:
            path_to_image = "{}/{}".format(self.path_to_data, file_name)

            try:
                im_frame = Image.open(path_to_image)
                img = np.asarray(im_frame, dtype="float32")
                img /= 255

                if self.augment_zoom_only:
                    img = random_zoom(img, zoom_range=(0.85, 1.15), channel_axis=2, row_axis=0, col_axis=1,
                                      fill_mode='constant', cval=0.0)
                elif self.augment:
                    img = random_zoom(img, zoom_range=(0.85, 1.15), channel_axis=2, row_axis=0, col_axis=1,
                                        fill_mode='constant', cval=0.0)
                    img = ab.HorizontalFlip()(image=img)["image"]
                    img = ab.VerticalFlip()(image=img)["image"]

                data_x.append(img)
                data_y.append(0)
            except:
                print("Error while loading image {}.".format(path_to_image))
                continue

        data_x = np.stack(data_x)
        data_y = np.stack(data_y)

        return data_x, data_y
Ejemplo n.º 2
0
 def test_img_transforms(self):
   x = np.random.random((3, 200, 200))
   _ = preprocessing_image.random_rotation(x, 20)
   _ = preprocessing_image.random_shift(x, 0.2, 0.2)
   _ = preprocessing_image.random_shear(x, 2.)
   _ = preprocessing_image.random_zoom(x, (0.5, 0.5))
   _ = preprocessing_image.apply_channel_shift(x, 2, 2)
   _ = preprocessing_image.apply_affine_transform(x, 2)
   with self.assertRaises(ValueError):
     preprocessing_image.random_zoom(x, (0, 0, 0))
   _ = preprocessing_image.random_channel_shift(x, 2.)
 def rand_zoom(x):
     return random_zoom(x,
                        zoom_range=(0.85, 1.15),
                        channel_axis=2,
                        row_axis=0,
                        col_axis=1,
                        fill_mode='constant',
                        cval=0.0)
    def data_generation(self, list_files_temp):
        data_x = []
        data_y = []

        for c in list_files_temp:
            image = self.load_image(c)
            label = self.dataset.iloc[c][1]

            if self.augment:
                image = random_zoom(image,
                                    zoom_range=(0.85, 1.15),
                                    channel_axis=2,
                                    row_axis=0,
                                    col_axis=1,
                                    fill_mode='constant',
                                    cval=0.0)
                image = ab.HorizontalFlip()(image=image)["image"]
                image = ab.VerticalFlip()(image=image)["image"]

            if self.multilabel:
                if label == 0:
                    label = [1, 0, 0, 0, 0]
                elif label == 1:
                    label = [1, 1, 0, 0, 0]
                elif label == 2:
                    label = [1, 1, 1, 0, 0]
                elif label == 3:
                    label = [1, 1, 1, 1, 0]
                elif label == 4:
                    label = [1, 1, 1, 1, 1]
                label = np.array(label)

            data_x.append(image)
            data_y.append(label)

        data_x = np.stack(data_x)
        data_y = np.stack(data_y)

        return data_x, data_y