renaming
This commit is contained in:
parent
8c7e3e29f5
commit
7f37f841dd
@ -9,9 +9,9 @@ logger.setLevel(logging.DEBUG)
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("estimator_type", ["mock", "keras"])
|
@pytest.mark.parametrize("estimator_type", ["mock", "keras"])
|
||||||
def test_predict(classifier, input_batch, expected_batch_string_labels):
|
def test_predict(classifier, input_batch, batch_of_expected_string_labels):
|
||||||
predictions = classifier.predict(input_batch)
|
predictions = classifier.predict(input_batch)
|
||||||
assert predictions == expected_batch_string_labels
|
assert predictions == batch_of_expected_string_labels
|
||||||
|
|
||||||
|
|
||||||
def test_batch_format(input_batch):
|
def test_batch_format(input_batch):
|
||||||
|
|||||||
@ -37,7 +37,7 @@ def image_extractor(extractor_type):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def image_classifier(classifier, monkeypatch, expected_batch_string_labels):
|
def image_classifier(classifier, monkeypatch, batch_of_expected_string_labels):
|
||||||
return ImageClassifier(classifier, preprocessor=BasicPreprocessor())
|
return ImageClassifier(classifier, preprocessor=BasicPreprocessor())
|
||||||
|
|
||||||
|
|
||||||
@ -129,18 +129,34 @@ def input_size(request):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def expected_batch_string_labels(expected_batch_numeric_labels, classes):
|
def batch_of_expected_string_labels(batch_of_expected_numeric_labels, classes):
|
||||||
return map_labels(expected_batch_numeric_labels, classes)
|
return map_labels(batch_of_expected_numeric_labels, classes)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def expected_batch_numeric_labels(batch_size, classes):
|
def batch_of_expected_numeric_labels(batch_size, classes):
|
||||||
return random.choices(range(len(classes)), k=batch_size)
|
return random.choices(range(len(classes)), k=batch_size)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def output_batch_generator(expected_batch_numeric_labels):
|
def batch_of_expected_label_to_probability_mappings(batch_of_expected_probability_arrays, classes):
|
||||||
return iter(expected_batch_numeric_labels)
|
|
||||||
|
def map_probabilities(probabilities):
|
||||||
|
lbl2prob = dict(sorted(zip(classes, probabilities), key=itemgetter(1), reverse=True))
|
||||||
|
most_likely = [*lbl2prob][0]
|
||||||
|
return {"label": most_likely, "probabilities": lbl2prob}
|
||||||
|
|
||||||
|
return list(map(map_probabilities, batch_of_expected_probability_arrays))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def batch_of_expected_probability_arrays(batch_size, classes):
|
||||||
|
return [np.random.uniform(size=len(classes)) for _ in range(batch_size)]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def output_batch_generator(batch_of_expected_numeric_labels):
|
||||||
|
return iter(batch_of_expected_numeric_labels)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|||||||
@ -7,8 +7,8 @@ from image_prediction.extractor_classifier.extractor_classifier import Extractor
|
|||||||
|
|
||||||
@pytest.mark.parametrize("extractor_type", ["mock"])
|
@pytest.mark.parametrize("extractor_type", ["mock"])
|
||||||
@pytest.mark.parametrize("estimator_type", ["mock", "keras"])
|
@pytest.mark.parametrize("estimator_type", ["mock", "keras"])
|
||||||
def test_extractor_classifier(image_extractor, image_classifier, images, expected_batch_string_labels):
|
def test_extractor_classifier(image_extractor, image_classifier, images, batch_of_expected_string_labels):
|
||||||
extractor_classifier = ExtractorClassifier(image_extractor, image_classifier)
|
extractor_classifier = ExtractorClassifier(image_extractor, image_classifier)
|
||||||
results = extractor_classifier(images)
|
results = extractor_classifier(images)
|
||||||
labels = list(map(itemgetter("prediction"), results))
|
labels = list(map(itemgetter("prediction"), results))
|
||||||
assert labels == expected_batch_string_labels
|
assert labels == batch_of_expected_string_labels
|
||||||
|
|||||||
@ -4,9 +4,9 @@ from image_prediction.utils import chunk_iterable
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("estimator_type", ["mock", "keras"])
|
@pytest.mark.parametrize("estimator_type", ["mock", "keras"])
|
||||||
def test_predict(image_classifier, images, expected_batch_string_labels):
|
def test_predict(image_classifier, images, batch_of_expected_string_labels):
|
||||||
predictions = list(image_classifier.predict(images))
|
predictions = list(image_classifier.predict(images))
|
||||||
assert predictions == expected_batch_string_labels
|
assert predictions == batch_of_expected_string_labels
|
||||||
|
|
||||||
|
|
||||||
def test_chunk_iterable_exact_split():
|
def test_chunk_iterable_exact_split():
|
||||||
|
|||||||
@ -1,6 +1,11 @@
|
|||||||
from image_prediction.label_mapper.mappers.numeric import IndexLabelMapper
|
from image_prediction.label_mapper.mappers.numeric import IndexLabelMapper
|
||||||
|
|
||||||
|
|
||||||
def test_index_label_mapper(expected_batch_numeric_labels, expected_batch_string_labels, classes):
|
def test_index_label_mapper(batch_of_expected_numeric_labels, batch_of_expected_string_labels, classes):
|
||||||
mapper = IndexLabelMapper(classes)
|
mapper = IndexLabelMapper(classes)
|
||||||
assert list(mapper(expected_batch_numeric_labels)) == expected_batch_string_labels
|
assert list(mapper(batch_of_expected_numeric_labels)) == batch_of_expected_string_labels
|
||||||
|
|
||||||
|
|
||||||
|
# def test_array_label_mapper(expected_batch_array, batch_of_expected_label_to_probability_mappings, classes):
|
||||||
|
# mapper = ProbabilityMapper(classes)
|
||||||
|
# assert list(mapper(expected_batch_numeric_labels)) == expected_batch_string_labels
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user