Module brevettiai.tests.test_model_metadata
Expand source code
import unittest
from itertools import chain
from brevettiai.model.metadata import ModelMetadata
from brevettiai.model.metadata.image_segmentation import ImageSegmentationModelMetadata
class ParsingException(Exception):
pass
class TestModelMetadata(unittest.TestCase):
metadata = [
"""
{
"id": "5f0bc78e-8470-403e-a257-f7310bb41297",
"run_id": "0000-00-00 00:00:00",
"name": "minimal_metadata",
"producer": "Manual",
"host_name": null
}
""",
"""
{
"id": "5f0bc78e-8470-403e-a257-f7310bb41298",
"run_id": "0000-00-00 00:00:00",
"name": "simple_metadata_with_host",
"producer": "Manual",
"host_name": "http://platform.brevetti.ai"
}
""",
]
image_segmentation_metadata = [
"""
{
"id": "c5daf50b-4d77-4435-9f15-e4148fbac032",
"run_id": "2022-01-28T132225",
"name": "Particle segmentation Emil data 39",
"producer": "ImageSegmentation",
"host_name": "https://platform.brevetti.ai",
"classes": [
"Container",
"Miniscus",
"Particle",
"Bubble",
"Good"
],
"suggested_input_shape": [
480,
360
],
"zoom_factor": 1.0,
"image_pipeline": {
"target_size": [150, 50],
"rois": [[[50,0],[100,150]]],
"roi_mode": "concatenate_height",
"path_key": "path",
"output_key": "img",
"color_mode": "greyscale",
"segmentation": {
"classes": [
"Container",
"Miniscus",
"Particle",
"Bubble",
"Good"
],
"mapping": {
"Container": "Container",
"Miniscus": "Container|Miniscus",
"Particle": "Container|Particle",
"Bubble": "Bubble|Container",
"Good": "Good",
"container": "Container",
"miniscus": "Container|Miniscus",
"particle": "Container|Particle",
"bubble": "Bubble|Container",
"good": "Good"
},
"sparse": false,
"input_key": "segmentation_path",
"output_key": "segmentation"
},
"keep_aspect_ratio": false,
"rescale": "None",
"resize_method": "bilinear",
"antialias": false,
"padding_mode": "CONSTANT",
"center_padding": false
},
"multi_frame_imager": {
"frames": [
-1,
0,
1
]
},
"annotation_pooling": {
"extra": {},
"pooling_method": "max",
"input_key": "segmentation",
"output_key": "downscaled_annotation",
"pool_size": [
8,
8
]
}
}
"""
]
def test_ensure_all_examples_are_valid_with_modelmetadata(self):
for data in chain(self.metadata, self.image_segmentation_metadata):
try:
ModelMetadata.parse_raw(data)
except Exception as e:
raise ParsingException(f"Error parsing: \n{data}") from e
def test_ensure_examples_are_valid_with_imagesegmentationmodelmetadata(self):
for data in self.image_segmentation_metadata:
try:
ImageSegmentationModelMetadata.parse_raw(data)
except Exception as e:
raise ParsingException(f"Error parsing: \n{data}") from e
if __name__ == '__main__':
unittest.main()
Classes
class ParsingException (*args, **kwargs)
-
Common base class for all non-exit exceptions.
Expand source code
class ParsingException(Exception): pass
Ancestors
- builtins.Exception
- builtins.BaseException
class TestModelMetadata (methodName='runTest')
-
A class whose instances are single test cases.
By default, the test code itself should be placed in a method named 'runTest'.
If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.
Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.
If it is necessary to override the init method, the base class init method must always be called. It is important that subclasses should not change the signature of their init method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.
When subclassing TestCase, you can set these attributes: * failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'. * longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed. * maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
Expand source code
class TestModelMetadata(unittest.TestCase): metadata = [ """ { "id": "5f0bc78e-8470-403e-a257-f7310bb41297", "run_id": "0000-00-00 00:00:00", "name": "minimal_metadata", "producer": "Manual", "host_name": null } """, """ { "id": "5f0bc78e-8470-403e-a257-f7310bb41298", "run_id": "0000-00-00 00:00:00", "name": "simple_metadata_with_host", "producer": "Manual", "host_name": "http://platform.brevetti.ai" } """, ] image_segmentation_metadata = [ """ { "id": "c5daf50b-4d77-4435-9f15-e4148fbac032", "run_id": "2022-01-28T132225", "name": "Particle segmentation Emil data 39", "producer": "ImageSegmentation", "host_name": "https://platform.brevetti.ai", "classes": [ "Container", "Miniscus", "Particle", "Bubble", "Good" ], "suggested_input_shape": [ 480, 360 ], "zoom_factor": 1.0, "image_pipeline": { "target_size": [150, 50], "rois": [[[50,0],[100,150]]], "roi_mode": "concatenate_height", "path_key": "path", "output_key": "img", "color_mode": "greyscale", "segmentation": { "classes": [ "Container", "Miniscus", "Particle", "Bubble", "Good" ], "mapping": { "Container": "Container", "Miniscus": "Container|Miniscus", "Particle": "Container|Particle", "Bubble": "Bubble|Container", "Good": "Good", "container": "Container", "miniscus": "Container|Miniscus", "particle": "Container|Particle", "bubble": "Bubble|Container", "good": "Good" }, "sparse": false, "input_key": "segmentation_path", "output_key": "segmentation" }, "keep_aspect_ratio": false, "rescale": "None", "resize_method": "bilinear", "antialias": false, "padding_mode": "CONSTANT", "center_padding": false }, "multi_frame_imager": { "frames": [ -1, 0, 1 ] }, "annotation_pooling": { "extra": {}, "pooling_method": "max", "input_key": "segmentation", "output_key": "downscaled_annotation", "pool_size": [ 8, 8 ] } } """ ] def test_ensure_all_examples_are_valid_with_modelmetadata(self): for data in chain(self.metadata, self.image_segmentation_metadata): try: ModelMetadata.parse_raw(data) except Exception as e: raise ParsingException(f"Error parsing: \n{data}") from e def test_ensure_examples_are_valid_with_imagesegmentationmodelmetadata(self): for data in self.image_segmentation_metadata: try: ImageSegmentationModelMetadata.parse_raw(data) except Exception as e: raise ParsingException(f"Error parsing: \n{data}") from e
Ancestors
- unittest.case.TestCase
Class variables
var image_segmentation_metadata
var metadata
Methods
def test_ensure_all_examples_are_valid_with_modelmetadata(self)
-
Expand source code
def test_ensure_all_examples_are_valid_with_modelmetadata(self): for data in chain(self.metadata, self.image_segmentation_metadata): try: ModelMetadata.parse_raw(data) except Exception as e: raise ParsingException(f"Error parsing: \n{data}") from e
def test_ensure_examples_are_valid_with_imagesegmentationmodelmetadata(self)
-
Expand source code
def test_ensure_examples_are_valid_with_imagesegmentationmodelmetadata(self): for data in self.image_segmentation_metadata: try: ImageSegmentationModelMetadata.parse_raw(data) except Exception as e: raise ParsingException(f"Error parsing: \n{data}") from e