Beispiel #1
0
    def __data_generator(self, batch_samples):
        # initialize images and labels tensors for faster processing
        X = np.empty((len(batch_samples), *self.img_crop_dims, 3))
        y = np.empty((len(batch_samples), self.n_classes))

        for i, sample in enumerate(batch_samples):
            # load and randomly augment image
            img_file = os.path.join(
                self.img_dir, '{}.{}'.format(sample['image_id'],
                                             self.img_format))

            img = utils.load_image(img_file, self.img_load_dims)
            if img is not None:
                img = utils.random_crop(img, self.img_crop_dims)
                img = utils.random_horizontal_flip(img)
                X[i, ] = img

            # normalize labels
            y[i, ] = utils.normalize_labels(sample['label'])

        # apply basenet specific preprocessing
        # input is 4D numpy array of RGB values within [0, 255]
        X = self.basenet_preprocess(X)

        return X, y
    def __data_generator(self, batch_samples):
        # initialize images and labels tensors for faster processing
        X = np.empty((len(batch_samples), *self.img_load_dims, 3))
        y = np.empty((len(batch_samples), self.n_classes))

        for i, sample in enumerate(batch_samples):
            # load and randomly augment image
            img_file = os.path.join(self.img_dir, '{}.{}'.format(sample['image_id'], self.img_format))
            img = utils.load_image(img_file, self.img_load_dims)
            if img is not None:
                X[i, ] = img

            # normalize labels
            if sample.get('label') is not None:
                y[i, ] = utils.normalize_labels(sample['label'])

        # apply basenet specific preprocessing
        # input is 4D numpy array of RGB values within [0, 255]
        X = self.basenet_preprocess(X)

        return X, y
    def test_normalize_label(self):
        labels = np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])

        normed_label = utils.normalize_labels(labels)
        np.testing.assert_array_equal(np.array([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1]), normed_label)
Beispiel #4
0
    def test_normalize_label(self):
        labels = np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])

        normed_label = utils.normalize_labels(labels)
        np.testing.assert_array_equal(
            np.array([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1]), normed_label)