Arguments#

class deeptrack.features.Arguments(_input: Any | None = None, **kwargs: Any)#

Bases: Feature

A convenience container for pipeline arguments.

Arguments allows dynamic control of pipeline behavior by providing a container for arguments that can be modified or overridden at runtime. This is particularly useful when working with parametrized pipelines, such as toggling behaviors based on whether an array is a label or a raw input.

Parameters#

**kwargs: Any

Properties to expose as pipeline arguments.

Methods#

get(inputs, **kwargs) -> Any

Passes the inputs through unchanged, while allowing for property overrides.

Examples#

>>> import deeptrack as dt

Create a temporary image file:

>>> import numpy as np
>>> import PIL, tempfile
>>>
>>> test_image_array = (np.ones((50, 50)) * 128).astype(np.uint8)
>>> temp_png = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
>>> PIL.Image.fromarray(test_image_array).save(temp_png.name)

A typical use-case is:

>>> arguments = dt.Arguments(noise_level=0.0)
>>> image_pipeline = (
...     dt.LoadImage(path=temp_png.name)
...     >> dt.Gaussian(sigma=arguments.noise_level)  # Image with no noise
... )
>>> image_pipeline.bind_arguments(arguments)
>>> image = image_pipeline()
>>> image.std()
0.0

Change the argument:

>>> image = image_pipeline(noise_level=1.0)  # Image with added noise
>>> image.std()
1.0104364326447652

For a conditional dependence, create a local link to the property as follows:

>>> arguments = dt.Arguments(is_label=False)
>>> image_pipeline = (
...     dt.LoadImage(path=temp_png.name)
...     >> dt.Gaussian(
...         local_is_label=arguments.is_label,
...         sigma=lambda local_is_label: 1 if local_is_label else 0,
...     )
... )
>>> image_pipeline.bind_arguments(arguments)
>>> image = image_pipeline()  # Image with added noise
>>> image.std()
0.9994058570249776
>>> image = image_pipeline(is_label=True)  # Raw image with no noise
>>> image.std()
0.0

As with any feature, all arguments can be passed by unpacking the properties dictionary:

>>> arguments = dt.Arguments(is_label=False, noise_sigma=5)
>>> image_pipeline = (
...     dt.LoadImage(path=temp_png.name)
...     >> dt.Gaussian(
...         sigma=lambda is_label, noise_sigma: (
...             0 if is_label else noise_sigma
...         ),
...         **arguments.properties,
...     )
... )
>>> image_pipeline.bind_arguments(arguments)
>>> image = image_pipeline()  # Image with added noise
>>> image.std()
5.002151761964336
>>> image = image_pipeline(is_label=True)  # Raw image with no noise
>>> image.std()
0.0

Remove the temporary image:

>>> import os
>>>
>>> os.remove(temp_png.name)

Methods Summary

get(inputs, **kwargs)

Return the inputs and allow property overrides.

Methods Documentation

get(inputs: Any, **kwargs: Any) Any#

Return the inputs and allow property overrides.

This method does not modify the inputs but provides a mechanism for overriding arguments dynamically during pipeline execution.

Parameters#

inputs: Any

The inputs to be passed through unchanged.

**kwargs: Any

Key-value pairs for overriding pipeline properties.

Returns#

Any

The unchanged inputs.