trw.datasets.dataset_fake_symbols
¶
Module Contents¶
Classes¶
Base class for protocol classes. Protocol classes are defined as: |
Functions¶
|
|
|
|
|
|
|
|
|
|
|
Create artificial 2D for classification and segmentation problems |
- trw.datasets.dataset_fake_symbols._noisy(image: numpy.ndarray, noise_type: typing_extensions.Literal[_noisy.gauss, poisson, s & p, speckle]) numpy.ndarray ¶
- Parameters
image – a numpy image (float) in range [0..255]
noise_type – the type of noise. Must be one of:
noise. (* 'gauss' Gaussian-distributed additive) –
data. (* 'poisson' Poisson-distributed noise generated from the) –
1. (* 's&p' Replaces random pixels with 0 or) –
n*image (* 'speckle' Multiplicative noise using out = image +) – uniform noise with specified mean & variance
is (where n) – uniform noise with specified mean & variance
- Returns
noisy image
- trw.datasets.dataset_fake_symbols._random_location(image_shape: numpy.ndarray, figure_shape) numpy.ndarray ¶
- trw.datasets.dataset_fake_symbols._random_color() numpy.ndarray ¶
- trw.datasets.dataset_fake_symbols._add_shape(imag, mask, shape, shapes_added, scale_factor, color, min_overlap_distance=30)¶
- trw.datasets.dataset_fake_symbols._create_image(shape, objects, nb_classes_at_once=None, max_classes=None, background=255)¶
- Parameters
shape – the shape of an image [height, width]
nb_classes_at_once – the number of classes to be included in each sample. If None, all the classes will be included
max_classes – the maximum number of classes to be used. If None, all classes can be used, else a random subset
- Returns
image, mask and shape information
- class trw.datasets.dataset_fake_symbols.ShapeCreator¶
Bases:
typing_extensions.Protocol
Base class for protocol classes. Protocol classes are defined as:
class Proto(Protocol): def meth(self) -> int: ...
Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example:
class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check
See PEP 544 for details. Protocol classes decorated with @typing_extensions.runtime act as simple-minded runtime protocol that checks only the presence of given attributes, ignoring their type signatures.
Protocol classes can be generic, they are defined as:
class GenProto(Protocol[T]): def meth(self) -> T: ...
- __call__(self, global_scale_factor: float) Dict[str, Callable[[Any], Tuple[numpy.ndarray, numpy.ndarray, List[Tuple[str, numpy.ndarray]]]]] ¶
- trw.datasets.dataset_fake_symbols.create_fake_symbols_datasset(nb_samples: int, image_shape: trw.basic_typing.ShapeX, dataset_name: str, shapes_fn: ShapeCreator, ratio_valid: float = 0.2, nb_classes_at_once: Optional[int] = None, global_scale_factor: float = 1.0, normalize_0_1: bool = True, noise_fn: Callable[[numpy.ndarray], numpy.ndarray] = functools.partial(_noisy, noise_type='poisson'), max_classes: Optional[int] = None, batch_size: int = 64, background: int = 255) trw.basic_typing.Datasets ¶
Create artificial 2D for classification and segmentation problems
This dataset will randomly create shapes at random location & color with a segmentation map.
- Parameters
nb_samples – the number of samples to be generated
image_shape – the shape of an image [height, width]
ratio_valid – the ratio of samples to be used for the validation split
nb_classes_at_once – the number of classes to be included in each sample. If None, all the classes will be included
global_scale_factor – the scale of the shapes to generate
noise_fn – a function to create noise in the image
shapes_fn – the function to create the different shapes
normalize_0_1 – if True, the data will be normalized (i.e., image & position will be in range [0..1])
max_classes – the total number of classes available
batch_size – the size of the batch for the dataset
background – the background value of the sample (before normalization if normalize_0_1 is True)
dataset_name – the name of the returned dataset
- Returns
a dict containing the dataset fake_symbols_2d with train and valid splits with features image, mask, classification, <shape_name>_center