-
Notifications
You must be signed in to change notification settings - Fork 0
/
_TestIC.py
43 lines (38 loc) · 1.4 KB
/
_TestIC.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from wai.common.cli.options import TypedOption
from wai.annotations.core.component import ProcessorComponent
from wai.annotations.core.stream import ThenFunction, DoneFunction
from wai.annotations.core.stream.util import RequiresNoFinalisation
from wai.annotations.domain.image.classification import ImageClassificationInstance
OUTPUT_FILENAME = "filename"
OUTPUT_DIMENSIONS = "dimensions"
OUTPUT_LABEL = "label"
OUTPUTS = [
OUTPUT_FILENAME,
OUTPUT_DIMENSIONS,
OUTPUT_LABEL,
]
class TestIC(
RequiresNoFinalisation,
ProcessorComponent[ImageClassificationInstance, ImageClassificationInstance]
):
output: str = TypedOption(
"--output",
type=str,
default=OUTPUT_FILENAME,
help="the information to output: %s" % "|".join(OUTPUTS)
)
def process_element(
self,
element: ImageClassificationInstance,
then: ThenFunction[ImageClassificationInstance],
done: DoneFunction
):
if self.output == OUTPUT_FILENAME:
self.logger.info(element.data.filename)
elif self.output == OUTPUT_DIMENSIONS:
self.logger.info("%d,%d" % (element.data.width, element.data.height))
elif self.output == OUTPUT_LABEL:
self.logger.info(element.annotations.label)
else:
raise Exception("Unknown output type (%s): %s" % ("|".join(OUTPUTS), self.output))
then(element)