-
Notifications
You must be signed in to change notification settings - Fork 646
/
base.py
47 lines (32 loc) · 1.17 KB
/
base.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
44
45
46
47
"""Base visualization generator."""
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
from abc import ABC, abstractmethod
from collections.abc import Iterator
from dataclasses import dataclass
from enum import Enum
from pathlib import Path
import numpy as np
@dataclass
class GeneratorResult:
"""Generator result.
All visualization generators are expected to return this object.
It is to ensure that the result is consistent across all generators.
"""
image: np.ndarray
file_name: str | Path | None = None
class VisualizationStep(str, Enum):
"""Identify step on which to generate images."""
BATCH = "batch"
STAGE_END = "stage_end"
class BaseVisualizer(ABC):
"""Base visualization generator."""
def __init__(self, visualize_on: VisualizationStep) -> None:
self.visualize_on = visualize_on
@abstractmethod
def generate(self, **kwargs) -> Iterator[GeneratorResult]:
"""Generate images and return them as an iterator."""
raise NotImplementedError
def __call__(self, **kwargs) -> Iterator[GeneratorResult]:
"""Call generate method."""
return self.generate(**kwargs)