Arguments#
- class deeptrack.features.Arguments(_input: Any = [], **kwargs: Dict[str, Any])#
Bases:
Feature
A convenience container for pipeline arguments.
The Arguments feature 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 parameterized pipelines, such as toggling behaviors based on whether an image is a label or a raw input.
Methods#
- get(image, **kwargs)
Passes the input image through unchanged, while allowing for property overrides.
Examples#
A typical use-case is:
>>> arguments = Arguments(is_label=False) >>> image_loader = ( ... LoadImage(path="./image.png") >> ... GaussianNoise(sigma = (1 - arguments.is_label) * 5) ... ) >>> image_loader.bind_arguments(arguments)
>>> image_loader() # Image with added noise. >>> image_loader(is_label=True) # Raw image with no noise.
For a non-mathematical dependence, create a local link to the property as follows:
>>> arguments = Arguments(is_label=False) >>> image_loader = ( ... LoadImage(path="./image.png") >> ... GaussianNoise( ... is_label=arguments.is_label, ... sigma=lambda is_label: 0 if is_label else 5 ... ) ... ) >>> image_loader.bind_arguments(arguments)
>>> image_loader() # Image with added noise >>> image_loader(is_label=True) # Raw image with no noise
Keep in mind that, if any dependent property is non-deterministic, they may permanently change:
>>> arguments = Arguments(noise_max_sigma=5) >>> image_loader = ( ... LoadImage(path="./image.png") >> ... GaussianNoise( ... noise_max_sigma=5, ... sigma=lambda noise_max_sigma: rand() * noise_max_sigma ... ) ... )
>>> image_loader.bind_arguments(arguments)
>>> image_loader().get_property("sigma") # Example: 3.27... >>> image_loader(noise_max_sigma=0) # 0 >>> image_loader().get_property("sigma") # Example: 1.93...
As with any feature, all arguments can be passed by deconstructing the properties dict:
>>> arguments = Arguments(is_label=False, noise_sigma=5) >>> image_loader = ( ... LoadImage(path="./image.png") >> ... GaussianNoise( ... sigma=lambda is_label, noise_sigma: ( ... 0 if is_label else noise_sigma ... ) ... **arguments.properties ... ) ... ) >>> image_loader.bind_arguments(arguments)
>>> image_loader() # Image with added noise. >>> image_loader(is_label=True) # Raw image with no noise.
Methods Summary
get
(image, **kwargs)Process the input image and allow property overrides.
Methods Documentation
- get(image: Any, **kwargs: Dict[str, Any]) Any #
Process the input image and allow property overrides.
This method does not modify the input image but provides a mechanism for overriding arguments dynamically during pipeline execution.
Parameters#
- imageAny
The input image to be passed through unchanged.
- **kwargsAny
Key-value pairs for overriding pipeline properties.
Returns#
- Any
The unchanged input image.