Esempio n. 1
0
def test_train(mocker):
    # assert that train gets run
    TEST_CONFIG_FILE = p.resolve().parent / 'test_configs' / 'config_train.yml'

    config = Config()

    m_dp, m_tc, m_t, m_e, m_c, m_l = mock_scripts(mocker)

    train(config, config_file=TEST_CONFIG_FILE)

    m_tc.assert_not_called()
    m_t.assert_called()

    # assert that train cloud gets run
    TEST_CONFIG_FILE = p.resolve(
    ).parent / 'test_configs' / 'config_train_cloud.yml'

    config = Config()

    m_dp, m_tc, m_t, m_e, m_c, m_l = mock_scripts(mocker)

    train(config, config_file=TEST_CONFIG_FILE)

    m_tc.assert_called()
    m_t.assert_not_called()
Esempio n. 2
0
def train(config: Config, **kwargs):
    """Train a CNN.

    Fine-tunes an ImageNet pre-trained CNN. The number of classes are derived from train_samples.json.
    After each epoch the model will be evaluated on val_samples.json.

    The best model (based on valuation accuracy) will be saved.

    Args:
        image_dir: Directory with image files.
        job_dir: Directory with train_samples, val_samples, and class_mapping.json.

    """
    commands.train(config, **kwargs)
Esempio n. 3
0
    def test_train(self):
        config = Config()

        assert not list(Path(TEST_JOB_DIR / 'models').glob('*.hdf5'))

        train(config, config_file=TEST_CONFIG_TRAIN)

        assert config.train['run'] == True
        assert config.train['cloud'] == False
        assert config.train['job_dir'] == str(TEST_JOB_DIR)
        assert config.train['image_dir'] == str(TEST_IMAGE_DIR_RES)

        assert config.dataprep['run'] == False
        assert config.evaluate['run'] == False
        assert config.cloud['run'] == False

        assert list(Path(TEST_JOB_DIR / 'models').glob('*.hdf5'))