示例#1
0
    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
示例#2
0
    def test_set_input_data(self):
        #Arrange
        checkpoint, _, _, _ = get_checkpoint()
        input_data = get_input_data()

        #Act
        checkpoint.set_input_data(input_data)

        #Assert
        self.assertIsNotNone(checkpoint._input_data)
        self.assertEqual(len(input_data), len(checkpoint._input_data))
示例#3
0
    def test_save(self):
        #Arrange
        input_data = get_input_data()
        input_data_file = InputDataFile()

        #Mocks
        input_data.to_csv = MagicMock()

        #Act
        input_data_file.save(input_data, batch_id, epoch_id)

        #Assert
        input_data.to_csv.assert_called_with(input_data_file.file_name(batch_id, epoch_id))
示例#4
0
    def test_on_batch_end_save_called(self):
        #Arrange
        batch_id = 1
        checkpoint, batch_input_files, _, _ = get_checkpoint()
        input_data = get_input_data()
        model = load_test_model()
        checkpoint.set_model(model)
        checkpoint.set_input_data(input_data)
        checkpoint.on_epoch_begin(epoch_id)
        checkpoint.on_batch_begin(batch_id)

        #Act & Assert
        self.on_batch_end(checkpoint, batch_id, batch_input_files)
示例#5
0
def get_train_args():
    input_data = get_input_data()
    model = load_test_model()
    input_params, training_params, image_generation_params, transformation_params = get_params()
    image_generation_params.num_classes = 64

    trainer = ImageTraining(
                    input_params,
                    training_params,
                    image_generation_params,
                    transformation_params,
                    MagicMock(),
                    summary = False)

    return model, input_data, trainer
示例#6
0
    def test_on_epoch_begin(self):
        #Arrange
        checkpoint, _, _, _ = get_checkpoint()
        checkpoint._model = MagicMock()
        input_data = get_input_data()
        input_data.to_csv = MagicMock()
        checkpoint.set_input_data(input_data)

        #Act
        checkpoint.on_epoch_begin(epoch_id)

        #Assert
        self.assertEqual(epoch_id, checkpoint._epoch_id)
        self.assertIsNotNone(checkpoint._epoch_response)
        self.assertEqual(epoch_id, checkpoint._epoch_response._epoch_id)
        self.on_input_data_save(checkpoint)
示例#7
0
    def test_dropbox_called(self):
        #Arrange
        checkpoint, _, _, _ = get_checkpoint(dropbox=get_dropbox())
        checkpoint._dropbox.upload = MagicMock()
        checkpoint._model = MagicMock()
        input_data = get_input_data()
        input_data.to_csv = MagicMock()
        checkpoint.set_input_data(input_data)
        input_file = InputDataFile().file_name(0, epoch_id)

        with mock_patch.object(Path, 'unlink') as mock_unlink:
            #Act
            checkpoint.on_epoch_begin(epoch_id)

            #Assert
            checkpoint._dropbox.upload.assert_called_with(input_file)
            mock_unlink.assert_called_once()
示例#8
0
    def test_on_epoch_end(self):
        #Arrange
        checkpoint, _, _, epoch_end_input_files = get_checkpoint()
        model = load_test_model()
        input_data = get_input_data()
        result_file = epoch_end_input_files[0]
        result_file.save = MagicMock()
        checkpoint.set_model(model)
        checkpoint.set_input_data(input_data)
        checkpoint.on_epoch_begin(epoch_id)
        checkpoint.on_batch_begin(batch_id)

        #Act
        checkpoint.on_epoch_end(epoch_id)

        #Assert
        self.on_result_file_save(checkpoint, result_file)
示例#9
0
    def test_init(self):
        #Arrange
        data = get_input_data()

        #Act
        _ = Rebalancing(data, label_col)