def test_load_and_featurize_single_column(model, size, array_path):
    """Test that all of the featurizations and attributes for each model are correct"""
    feat = ImageFeaturizer(model=model)
    feat.load_and_featurize_data(save_features=True,
                                 omit_time=True,
                                 omit_model=True,
                                 omit_depth=True,
                                 omit_output=True,
                                 **LOAD_DATA_ARGS)

    check_array = np.load(array_path)

    try:
        compare_featurizer_class(feat, size, check_array, **COMPARE_ARGS)
    finally:
        # Remove path to the generated csv at the end of the test
        if os.path.isdir('tests/ImageFeaturizer_testing/csv_tests'):
            shutil.rmtree('tests/ImageFeaturizer_testing/csv_tests')
        del feat
def test_writing_features_to_csv_with_robust_naming():
    """Make sure the featurizer writes the name correctly to csv with robust naming config"""
    f = ImageFeaturizer()
    f.load_and_featurize_data(save_features=True,
                              omit_time=True,
                              **LOAD_DATA_ARGS_MULT)
    check_array_path = '{}_squeezenet_depth-1_output-512'.format(CSV_NAME_MULT)
    full_check = '{}_full'.format(check_array_path)
    feature_check = '{}_features_only'.format(check_array_path)
    try:
        assert os.path.isfile(full_check)
        assert os.path.isfile(feature_check)
    finally:
        if os.path.isdir('tests/ImageFeaturizer_testing/csv_tests'):
            shutil.rmtree('tests/ImageFeaturizer_testing/csv_tests')

        if os.path.isfile('{}_full'.format(check_array_path)):
            os.remove('{}_full'.format(check_array_path))
            pass
        if os.path.isfile('{}_features_only'.format(check_array_path)):
            os.remove('{}_features_only'.format(check_array_path))
def test_load_and_featurize_data_multiple_columns(model, size, array_path):
    """Test featurizations and attributes for each model are correct with multiple image columns"""
    feat = ImageFeaturizer(model=model, auto_sample=True)
    feat.load_and_featurize_data(save_features=True,
                                 omit_time=True,
                                 omit_model=True,
                                 omit_depth=True,
                                 omit_output=True,
                                 **LOAD_DATA_ARGS_MULT)
    check_array = np.load(array_path)

    try:
        compare_featurizer_class(feat, size, check_array, **COMPARE_ARGS_MULT)
    finally:
        # Remove path to the generated csv at the end of the test
        if os.path.isdir('tests/ImageFeaturizer_testing/csv_tests'):
            shutil.rmtree('tests/ImageFeaturizer_testing/csv_tests')

        if os.path.isfile('{}_full'.format(CSV_NAME_MULT)):
            os.remove('{}_full'.format(CSV_NAME_MULT))
            pass
        if os.path.isfile('{}_features_only'.format(CSV_NAME_MULT)):
            os.remove('{}_features_only'.format(CSV_NAME_MULT))
        del feat
Exemple #4
0
def create_numpy_arrays(model):
    """Create the prediction arrays"""
    f = ImageFeaturizer(model=model, auto_sample=True)
    f.load_and_featurize_data(**LOAD_DATA_ARGS_MULT)
    np.save(CHECK_ARRAY_MULT.format(model), f.featurized_data)
    return f