Lambda#
- class deeptrack.features.Lambda(function: Callable[[...], Callable[[Any], Any]], **kwargs: Any)#
Bases:
FeatureApply a user-defined function to the input.
This feature allows applying a custom function to individual inputs in the input pipeline. The function parameter must be wrapped in an outer function that can depend on other properties of the pipeline. The inner function processes a single input.
Parameters#
- function: Callable[…, Callable[[Any], Any]]
A callable that produces a function. The outer function can accept additional arguments from the pipeline, while the inner function operates on a single input.
- **kwargs: Any
Additional keyword arguments passed to the parent Feature class.
Methods#
- get(inputs, function, **kwargs) -> Any
Applies the custom function to the inputs.
Examples#
>>> import deeptrack as dt
Define a factory function that returns a scaling function:
>>> def scale_function_factory(scale=2): ... def scale_function(image): ... return image * scale ... return scale_function
Create a Lambda feature that scales images by a factor of 5:
>>> lambda_feature = dt.Lambda(function=scale_function_factory, scale=5)
Create an array:
>>> import numpy as np >>> >>> input_array = np.ones((2, 3)) >>> input_array array([[1., 1., 1.], [1., 1., 1.]])
Apply the feature to the array:
>>> output_array = lambda_feature(input_array) >>> output_array array([[5., 5., 5.], [5., 5., 5.]])
Methods Summary
get(inputs, function, **kwargs)Apply the custom function to the input.
Methods Documentation
- get(inputs: Any, function: Callable[[Any], Any], **kwargs: Any) Any#
Apply the custom function to the input.
This method applies a user-defined function to transform the input. The function should be a callable that takes an input and returns a modified version of it.
Parameters#
- inputs: Any
The input to be processed.
- function: Callable[[Any], Any]
A callable function that takes an input and returns a transformed output.
- **kwargs: Any
Additional keyword arguments (unused in this implementation).
Returns#
- Any
The transformed output after applying the function.