def test_init(self): with self.assertRaises(ValueError): #Arrange bad_dataset_location = dataset_location / 'non_existent_location' args = get_args(None, bad_dataset_location) #Act _ = ImageGenerationParameters(args) args = get_args(model_name, dataset_location) _ = ImageGenerationParameters(args)
def get_inputs(cls, num_prediction_steps, num_results=None): #Arrange model = load_test_model() args = get_args(model_name, Path()) input_params = InputParameters(args) image_generation_params = ImageGenerationParameters(args) input_data = get_input_data() #Update input data parameters num_classes = len(set(input_data[image_generation_params.label_col])) image_generation_params_update = dict(num_classes=num_classes, image_cols=['Image']) update_params(image_generation_params, **image_generation_params_update) #Num results num_results = num_results or image_generation_params.batch_size * num_prediction_steps #Mocks prediction_results = np.zeros((num_results, num_classes)) for row_id in range(num_results): prediction_results[row_id, row_id % num_classes] = 1 model.predict_generator = MagicMock() model.predict_generator.return_value = prediction_results return model, input_data, input_params, image_generation_params, prediction_results
def test_init_invalid_args(self): #Arrange args = get_args(model_name, Path()) input_params = InputParameters(args) image_generation_params = ImageGenerationParameters(args) with self.assertRaises(ValueError): _ = Prediction(None, input_params, image_generation_params)
def get_params(): args = get_args(image_cols = ['Image']) input_params = InputParameters(args) training_params = TrainingParameters(args) image_generation_params = ImageGenerationParameters(args) transformation_params = ImageDataTransformation.Parameters(samplewise_mean = True) return input_params, training_params, image_generation_params, transformation_params
def test_update_params(self): #Arrange args = get_args(model_name, dataset_location) image_generation_params = ImageGenerationParameters(args) additional_kwargs = dict(num_classes=num_classes) #Act update_params(image_generation_params, **additional_kwargs) #Assert self.assertEqual(num_classes, image_generation_params.num_classes)
parser.add_argument( '-l', '--log_to_console', action = 'store_true', default = False, help = 'It enables logging to console') args = parser.parse_args() return args if __name__ == "__main__": #Parse commandline arguments args = parse_args() #Required params input_params = InputParameters(args) image_generation_params = ImageGenerationParameters(args) num_prediction_steps = args.num_prediction_steps dropbox_parameters = args.dropbox_parameters log_to_console = args.log_to_console #Initialize logging logging.initialize(__file__, log_to_console = log_to_console) logger = logging.get_logger(__name__) #Log input parameters logger.info('Running with parameters input_params: %s', input_params) logger.info('Additional parameters: image_generation_params: %s log_to_console: %s', image_generation_params, log_to_console) #Predictable randomness seed = 3
def get_input_and_image_generation_params(): args = get_args() input_data_params = InputParameters(args) image_generation_params = ImageGenerationParameters(args) return input_data_params, image_generation_params