Exemple #1
0
    def __init__(self,
                 input_params,
                 training_params,
                 image_generation_params,
                 transformation_params,
                 checkpoint_callback,
                 summary=True):
        """It initializes the training parameters.

        Arguments:
            input_params {operation.input.InputParameters} -- The input parameters for the training.    
            training_params {operation.input.TrainingParameters} -- The parameter to start training.
            image_generation_params {operation.input.ImageGenerationParameters} -- The parameters required for image data generation.
            checkpoint_callback {model.callback.BatchTrainStateCheckpoint} -- The state checkpoint callback.
        """
        #Required parameters
        self._input_params = input_params
        self._training_params = training_params
        self._image_generation_params = image_generation_params
        self._transformation_params = transformation_params
        self._checkpoint_callback = checkpoint_callback

        #Optional parameters
        self._summary = summary

        #Derived parameters
        self._transformer = ImageDataTransformation(
            parameters=self._transformation_params)

        #Logging
        self._logger = logging.get_logger(__name__)
    def test_transform_with_featurewise_mean_fit_not_called(self):
        #Arrange
        images = TestImageDataTransformation.get_featurewise_mean_examples()

        #Transformation object
        parameters = ImageDataTransformation.Parameters(featurewise_mean = True)
        transformation = ImageDataTransformation(parameters = parameters)

        with self.assertRaises(ValueError):
            transformation.transform(images)
    def transform_featurewise_std_normalization(self, featurewise_std_normalization, images, result):
        #Transformation object
        parameters = ImageDataTransformation.Parameters(featurewise_std_normalization = featurewise_std_normalization)
        transformation = ImageDataTransformation(parameters = parameters)

        #Fit and perform transformation
        transformation.fit(images)
        transformed_images = transformation.transform(images)
        transformed_std = transformed_images.std(axis = 0)

        #Assert
        self.assertTrue(np.allclose(transformed_std, result))
    def transform_horizontal_flip(self, horizontal_flip, images, results):
        #Transformation object
        parameters = ImageDataTransformation.Parameters(horizontal_flip = horizontal_flip, horizontal_flip_prob = 1.0)
        transformation = ImageDataTransformation(parameters = parameters)

        #Transform
        transformed_images = transformation.transform(images)

        #Assert
        self.assertTrue(
                np.array_equal(transformed_images, results),
                "transformed_images: {} != expected: {}".format(transformed_images, results))
    def transform_samplewise_mean(self, samplewise_mean, images, results):
        #Transformation object
        parameters = ImageDataTransformation.Parameters(samplewise_mean = samplewise_mean)
        transformation = ImageDataTransformation(parameters = parameters)

        #Transform
        transformed_images = transformation.transform(images)

        #Assert
        self.assertTrue(
            np.array_equal(transformed_images, results),
            "transformed_images: {} != expected: {}".format(transformed_images, results))
    def transform_affine(self, parameters):
        #Image dataset
        images = np.random.rand(5, 50, 50, 3)

        #Transformation object
        transformation = ImageDataTransformation(parameters = parameters)
        no_transformation = ImageDataTransformation()

        #Act
        transformed_images = transformation.transform(images)
        no_transformed_images = no_transformation.transform(images)

        #No transformation assertions
        np.testing.assert_array_almost_equal(
                        no_transformed_images,
                        images,
                        err_msg = "Unexpected transformation for parameters: {}".format(parameters))

        #Transformation assertions
        self.assertFalse(
                np.array_equal(transformed_images, images),
                "Expected rotation transformation for parameters: {}".format(parameters))
    def transform_featurewise_mean(self, featurewise_mean, images, result):
        #Transformation object
        parameters = ImageDataTransformation.Parameters(featurewise_mean = featurewise_mean)
        transformation = ImageDataTransformation(parameters = parameters)

        #Fit and perform transformation
        transformation.fit(images)
        transformed_images = transformation.transform(images)
        sum_image = transformed_images.sum(axis = 0)

        #Assert
        self.assertTrue(
                np.array_equal(sum_image, result),
                "Sum images: {} expected: {}".format(sum_image, result))
Exemple #8
0
        def __init__(self, transformation_params, num_output_images=1):
            """It initializes the augmentation parameters.

            Arguments:
                transformation_params {A ImageDataTransformation.Parameters object} -- The transformation parameters.
                num_output_images {int} -- The number of transformed images.
            """
            #Required parameters
            self._transformation_params = transformation_params
            self._num_output_images = num_output_images

            #Validation
            if self._transformation_params is None:
                raise ValueError('transformation_params must be valid')

            #Derived parameters
            self._transformer = ImageDataTransformation(
                self._transformation_params)
    def transform_samplewise_std_normalization(self, samplewise_std_normalization, images):
        #Transformation object
        parameters = ImageDataTransformation.Parameters(samplewise_std_normalization = samplewise_std_normalization)
        transformation = ImageDataTransformation(parameters = parameters)

        #Transform
        transformed_images = transformation.transform(images)

        #Compute standard deviation
        standard_deviations = np.std(transformed_images, axis = (1, 2, 3))

        #Assert
        if samplewise_std_normalization:
            self.assertAlmostEqual(
                np.sum(standard_deviations), 
                2.,
                places = 2,
                msg = "standard_deviations: {} != expected: 2.".format(standard_deviations))
        else:
            self.assertNotEqual(np.sum(standard_deviations), 2.)