Welcome to Ballfish’s documentation!¶
- ballfish.create_augmentation(operations: Sequence[Args]) Callable[[Datum, Random], Datum]¶
Main function to create augmentation function.
- class ballfish.distribution.Require(name: str, minimum: float | None = None, maximum: float | None = None, is_int: bool = False)¶
A way to limit
create_distribution()expected values
- ballfish.distribution.create_distribution(kwargs: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float, require: Require | None = None) Callable[[Random], float]¶
Available Distributions¶ Name
Parameters
Distribution
uniform
a=0, b=0.5
uniform
a=-0.75, b=0.75
truncnorm
mu=0.0, sigma=0.75, delta=1.0
truncnorm
mu=0.4, sigma=0.3, delta=1.0
truncnorm
mu=0.0, sigma=0.5, a=0.0, b=1.0
constant
value=0.25
randrange
start=-1, stop=2
choice
values = [-0.1, 0.1, 1]
choice
values = [(-0.1, 30), (0.1, 60), (1, 10)]
- Parameters:
require – optional
Requireclass that will ensure that distribution is in required range
Example¶
>>> ballfish.create_distribution({"name": "truncnorm", "a": -0.25, "b": 0.25}) <function create_distribution.<locals>._truncnorm at 0x7feb7e166b60>
- class ballfish.transformation.Datum(source: Tensor | None = None, quad: tuple[tuple[float, float], tuple[float, float], tuple[float, float], tuple[float, float]] | None = None, width: int | None = None, height: int | None = None, image: Tensor | None = None)¶
Input and output class for augmentation
- source¶
Main input that
Rasterizetakes as input. Expected to be in (N, C, H, W) format. This input unfortunately must be in torch.float{32,64} formats because torch’s torch.nn.functional.grid_sample doesn’t work with other types.
- quads: list[tuple[tuple[float, float], tuple[float, float], tuple[float, float], tuple[float, float]]]¶
rois
- height¶
Height
- class ballfish.transformation.Projective1pt(x: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float, y: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float)¶
Shifts one point of the quadrangle in random direction.
{ "name": "projective1pt", "x": {"name": "truncnorm", "a": -0.25, "b": 0.25}, "y": {"name": "uniform", "a": -0.25, "b": 0.25} }
- class ballfish.transformation.Projective4pt(x: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float, y: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float)¶
Shifts four point of the quadrangle in random direction.
{ "name": "projective4pt", "x": {"name": "truncnorm", "a": -0.25, "b": 0.25}, "y": {"name": "uniform", "a": -0.25, "b": 0.25} }
- class ballfish.transformation.Flip(direction: Literal['horizontal', 'vertical', 'primary_diagonal', 'secondary_diagonal'] = 'horizontal')¶
Flips the quadrangle vertically or horizontally. Only changes points order, that is, visually the quadrangle doesn’t change, but its visualization does.
For diagonal names see: https://en.wikipedia.org/wiki/Main_diagonal
- static horizontal(q: tuple[tuple[float, float], tuple[float, float], tuple[float, float], tuple[float, float]]) tuple[tuple[float, float], tuple[float, float], tuple[float, float], tuple[float, float]]¶
{"name": "flip", "direction": "horizontal"}
- static vertical(q: tuple[tuple[float, float], tuple[float, float], tuple[float, float], tuple[float, float]]) tuple[tuple[float, float], tuple[float, float], tuple[float, float], tuple[float, float]]¶
{"name": "flip", "direction": "vertical"}
- static primary_diagonal(q: tuple[tuple[float, float], tuple[float, float], tuple[float, float], tuple[float, float]]) tuple[tuple[float, float], tuple[float, float], tuple[float, float], tuple[float, float]]¶
{"name": "flip", "direction": "primary_diagonal"}
- static secondary_diagonal(q: tuple[tuple[float, float], tuple[float, float], tuple[float, float], tuple[float, float]]) tuple[tuple[float, float], tuple[float, float], tuple[float, float], tuple[float, float]]¶
{"name": "flip", "direction": "secondary_diagonal"}
- class ballfish.transformation.PaddingsAddition(top: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float = 0.0, right: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float = 0.0, bottom: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float = 0.0, left: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float = 0.0)¶
Adds random padding to the quadrangle sides.
{ "name": "paddings_addition", "top": {"name": "uniform", "a": 0, "b": 0.25}, "right": {"name": "uniform", "a": 0, "b": 0.25}, "bottom": {"name": "uniform", "a": 0, "b": 0.25}, "left": {"name": "uniform", "a": 0, "b": 0.25} }
- class ballfish.transformation.ProjectivePaddingsAddition(top: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float = 0.0, right: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float = 0.0, bottom: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float = 0.0, left: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float = 0.0)¶
Same as PaddingsAddition, but addition respects original projective transformation.
{ "name": "projective_paddings_addition", "top": {"name": "uniform", "a": 0, "b": 0.25}, "right": {"name": "uniform", "a": 0, "b": 0.25}, "bottom": {"name": "uniform", "a": 0, "b": 0.25}, "left": {"name": "uniform", "a": 0, "b": 0.25} }
- class ballfish.transformation.Rotate(angle_deg: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float)¶
Rotates the quadrangle around its center.
{ "name": "rotate", "angle_deg": {"name": "uniform", "a": 0, "b": 360} }
- class ballfish.transformation.ProjectiveShift(x: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float = 0.0, y: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float = 0.0)¶
Projectively shifts the quadrangle.
{ "name": "projective_shift", "x": {"name": "truncnorm", "a": -3.1, "b": 3.1} }
- class ballfish.transformation.Scale(factor: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float)¶
Scales the quadrangle to the factor specified in the distribution.
{ "name": "scale", "factor": {"name": "truncnorm", "a": 0.7, "b": 1.3} }
- class ballfish.transformation.Rasterize(mode: Literal['bilinear', 'nearest', 'bicubic'] = 'bilinear', padding_mode: Literal['zeros', 'border', 'reflection'] = 'zeros')¶
Rasterizes the image from quadrangle using projective transform and the size specified in
Datum.{"name": "rasterize"}
- class ballfish.transformation.Noise(std: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float, mean: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float | None = None, type: Literal['heteroscedastic', 'homoscedastic'] = 'homoscedastic')¶
Adds normal noise to the image numpy.random.RandomState.normal.
{ "name": "noise", "std": {"name": "truncnorm", "a": 0, "b": 0.1} }
{ "name": "noise", "std": {"name": "truncnorm", "a": 0, "b": 0.1}, "type": "heteroscedastic" }
- class ballfish.transformation.OperationTransform(per: Literal['channel', 'batch', 'tensor'])¶
Allow operation applying to “channel”, “batch” or “tensor”
- class ballfish.transformation.Add(value: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float | Sequence[UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float], per: Literal['channel', 'batch', 'tensor'] = 'tensor')¶
Add the value to Datum.image
{ "name": "add", "value": { "name": "truncnorm", "a": -0.333, "b": 0.333, } }
- class ballfish.transformation.Multiply(factor: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float | Sequence[UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float], per: Literal['channel', 'batch', 'tensor'] = 'tensor')¶
Multiply Datum.image by the factor
{ "name": "multiply", "factor": {"name": "truncnorm", "a": 0.333, "b": 3.0} }
- class ballfish.transformation.Divide(value: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float | Sequence[UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float], per: Literal['channel', 'batch', 'tensor'] = 'tensor')¶
Divide Datum.image by the value.
{"name": "divide", "value": 255}
- class ballfish.transformation.Pow(pow: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float | Sequence[UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float], per: Literal['channel', 'batch', 'tensor'] = 'tensor')¶
Raise Datum.image to the power of pow
{ "name": "pow", "pow": {"name": "truncnorm", "a": 0.6, "b": 3.0} }
- class ballfish.transformation.Log(base: Literal['2', 'e', '10'] = 'e')¶
Calculates one of the three logarithms for Datum.image
\(\ln\)¶
{"name": "log", "base": "e"}
- class ballfish.transformation.Clip(min: float, max: float)¶
Clip Datum.image value to min and max
{"name": "clip", "min": 0.0, "max": 1.0}
- class ballfish.transformation.Grayscale(num_output_channels: int = 1)¶
Average of all channels. Set num_output_channels to make number ou output channels not one.
{"name": "grayscale"}
- class ballfish.transformation.Sharpness(factor: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float)¶
Makes image sharper.
{ "name": "sharpness", "factor": {"name": "truncnorm", "a": 0.5, "b": 12} }
- class ballfish.transformation.Shading(value: UniformParams | TruncnormParams | ConstantParams | RandrangeParams | ChoiceParams | float)¶
Makes a random band darker.
{ "name": "shading", "value": {"name": "truncnorm", "a": -0.5, "b": 0.5} }
- class ballfish.transformation.Resize(width: int, height: int, antialias: bool = True, interpolation: Literal['nearest', 'nearest_exact', 'bilinear', 'bicubic'] = 'bilinear')¶
Changes the size of a tensor. Usually this function is not needed because resizing is done in rasterize step.
{"name": "resize", "width": 100, "height": 60}
- class ballfish.transformation.OneOf(operations: list[Args | Args | Args | Args | Args | Args | Args | Args | Args | Args | Args | Args | Args | Args | Args | Args | Args | Args | Args | Args | Args])¶
Apply one of the specified operations. In this mode, operation probabilities are used as weights, 1.0 by default
{ "name": "one_of", "operations": [ { "name": "shading", "value": { "name": "truncnorm", "a": -0.5, "b": 0.5 } }, { "name": "noise", "std": { "name": "truncnorm", "a": 0, "b": 0.1, }, "type": "heteroscedastic" } ] }