|
1 |
| -from typing import Any, Dict, Union |
| 1 | +from typing import Any, Dict, Optional, TYPE_CHECKING |
2 | 2 |
|
3 | 3 | import numpy as np
|
4 | 4 | import logging
|
|
15 | 15 | from pybsm.otf import darkCurrentFromDensity
|
16 | 16 | from nrtk.impls.perturb_image.generic.cv2.blur import GaussianBlurPerturber
|
17 | 17 | from nrtk.impls.perturb_image.pybsm.perturber import PybsmPerturber, PybsmSensor, PybsmScenario
|
18 |
| - |
19 |
| - GaussianBlurPerturberType = Union[GaussianBlurPerturber, None] |
20 |
| - PybsmPerturberType = Union[PybsmPerturber, None] |
21 | 18 | except ImportError:
|
22 | 19 | logger.info("Disabling NRTK transforms due to missing library/failing imports")
|
23 | 20 | ENABLED_NRTK_TRANSFORMS = False
|
| 21 | + |
| 22 | +if TYPE_CHECKING: |
| 23 | + GaussianBlurPerturberType = GaussianBlurPerturber |
| 24 | + PybsmPerturberType = PybsmPerturber |
| 25 | +else: |
24 | 26 | GaussianBlurPerturberType = None
|
25 | 27 | PybsmPerturberType = None
|
26 | 28 |
|
| 29 | +GaussianBlurPerturberArg = Optional[GaussianBlurPerturberType] |
| 30 | +PybsmPerturberArg = Optional[PybsmPerturberType] |
| 31 | + |
27 | 32 |
|
28 | 33 | def nrtk_transforms_available():
|
29 | 34 | return ENABLED_NRTK_TRANSFORMS
|
30 | 35 |
|
31 | 36 |
|
32 | 37 | class NrtkGaussianBlurTransform(ImageTransform):
|
33 |
| - def __init__(self, perturber: GaussianBlurPerturberType = None): |
| 38 | + def __init__(self, perturber: GaussianBlurPerturberArg = None): |
34 | 39 | if perturber is None:
|
35 | 40 | perturber = GaussianBlurPerturber()
|
36 | 41 |
|
@@ -160,7 +165,7 @@ def createSampleSensorAndScenario():
|
160 | 165 |
|
161 | 166 |
|
162 | 167 | class NrtkPybsmTransform(ImageTransform):
|
163 |
| - def __init__(self, perturber: PybsmPerturberType = None): |
| 168 | + def __init__(self, perturber: PybsmPerturberArg = None): |
164 | 169 | if perturber is None:
|
165 | 170 | sensor, scenario = createSampleSensorAndScenario()
|
166 | 171 | perturber = PybsmPerturber(sensor=sensor, scenario=scenario)
|
|
0 commit comments