dacapo.experiments.tasks.post_processors
Submodules
- dacapo.experiments.tasks.post_processors.argmax_post_processor
- dacapo.experiments.tasks.post_processors.argmax_post_processor_parameters
- dacapo.experiments.tasks.post_processors.dummy_post_processor
- dacapo.experiments.tasks.post_processors.dummy_post_processor_parameters
- dacapo.experiments.tasks.post_processors.post_processor
- dacapo.experiments.tasks.post_processors.post_processor_parameters
- dacapo.experiments.tasks.post_processors.threshold_post_processor
- dacapo.experiments.tasks.post_processors.threshold_post_processor_parameters
- dacapo.experiments.tasks.post_processors.watershed_post_processor
- dacapo.experiments.tasks.post_processors.watershed_post_processor_parameters
Classes
Dummy post-processor that stores some dummy data. The dummy data is a 10x10x10 |
|
Parameters for the dummy post-processor. The dummy post-processor will set |
|
Base class for post-processor parameters. Post-processor parameters are |
|
Base class of all post-processors. |
|
A post-processor that applies a threshold to the prediction. |
|
Parameters for the threshold post-processor. The threshold post-processor |
|
Post-processor that takes the argmax of the input array along the channel |
|
Parameters for the argmax post-processor. The argmax post-processor will set |
|
A post-processor that applies a watershed transformation to the |
|
Parameters for the watershed post-processor. |
Package Contents
- class dacapo.experiments.tasks.post_processors.DummyPostProcessor(detection_threshold: float)
Dummy post-processor that stores some dummy data. The dummy data is a 10x10x10 array filled with the value of the min_size parameter. The min_size parameter is specified in the parameters of the post-processor. The post-processor has a detection threshold that is used to determine if an object is detected.
- detection_threshold
The detection threshold.
- enumerate_parameters()
Enumerate all possible parameters of this post-processor.
- set_prediction()
Set the prediction array identifier.
- process()
Convert predictions into the final output.
Note
This class is abstract. Subclasses must implement the abstract methods. Once created, the values of its attributes cannot be changed.
- detection_threshold
- enumerate_parameters() Iterable[dacapo.experiments.tasks.post_processors.dummy_post_processor_parameters.DummyPostProcessorParameters]
Enumerate all possible parameters of this post-processor. Should return instances of
PostProcessorParameters.- Returns:
An iterable of PostProcessorParameters instances.
- Raises:
NotImplementedError – If the method is not implemented in the subclass.
Examples
>>> post_processor = DummyPostProcessor() >>> for parameters in post_processor.enumerate_parameters(): ... print(parameters) DummyPostProcessorParameters(id=0, min_size=1) DummyPostProcessorParameters(id=1, min_size=2) DummyPostProcessorParameters(id=2, min_size=3) DummyPostProcessorParameters(id=3, min_size=4) DummyPostProcessorParameters(id=4, min_size=5) DummyPostProcessorParameters(id=5, min_size=6) DummyPostProcessorParameters(id=6, min_size=7) DummyPostProcessorParameters(id=7, min_size=8) DummyPostProcessorParameters(id=8, min_size=9) DummyPostProcessorParameters(id=9, min_size=10)
Note
This method must be implemented in the subclass. It should return an iterable of PostProcessorParameters instances.
- set_prediction(prediction_array_identifier)
Set the prediction array identifier.
- Parameters:
prediction_array_identifier – The identifier of the array containing the model’s prediction.
- Raises:
NotImplementedError – If the method is not implemented in the subclass.
Examples
>>> post_processor = DummyPostProcessor() >>> post_processor.set_prediction("prediction")
Note
This method must be implemented in the subclass. It should set the prediction_array_identifier attribute.
- process(parameters, output_array_identifier, *args, **kwargs)
Convert predictions into the final output.
- Parameters:
parameters – The parameters of the post-processor.
output_array_identifier – The identifier of the output array.
num_workers – The number of workers to use.
chunk_size – The size of the chunks to process.
- Returns:
The output array.
- Raises:
NotImplementedError – If the method is not implemented in the subclass.
Examples
>>> post_processor = DummyPostProcessor() >>> post_processor.process(parameters, "output")
Note
This method must be implemented in the subclass. It should process the predictions and store the output in the output array.
- class dacapo.experiments.tasks.post_processors.DummyPostProcessorParameters
Parameters for the dummy post-processor. The dummy post-processor will set the output to 1 if the input is greater than the minimum size, and 0 otherwise.
- min_size
The minimum size. If the input is greater than this value, the output will be set to 1. Otherwise, the output will be set to 0.
- parameter_names()
Get the names of the parameters.
Note
This class is immutable. Once created, the values of its attributes cannot be changed.
- min_size: int
- class dacapo.experiments.tasks.post_processors.PostProcessorParameters
Base class for post-processor parameters. Post-processor parameters are immutable objects that define the parameters of a post-processor. The parameters are used to configure the post-processor.
- id
The identifier of the post-processor parameter.
- parameter_names()
Get the names of the parameters.
Note
This class is immutable. Once created, the values of its attributes cannot be changed.
- id: int
- property parameter_names: List[str]
Get the names of the parameters.
- Returns:
A list of parameter names.
- Raises:
NotImplementedError – If the method is not implemented in the subclass.
Examples
>>> parameters = PostProcessorParameters(0) >>> parameters.parameter_names ["id"]
Note
This method must be implemented in the subclass. It should return a list of parameter names.
- class dacapo.experiments.tasks.post_processors.PostProcessor
Base class of all post-processors.
A post-processor takes a model’s prediction and converts it into the final output (e.g., per-voxel class probabilities into a semantic segmentation). A post-processor can have multiple parameters, which can be enumerated using the enumerate_parameters method. The process method takes a set of parameters and applies the post-processing to the prediction.
- prediction_array_identifier
The identifier of the array containing the model’s prediction.
- enumerate_parameters()
Enumerate all possible parameters of this post-processor.
- set_prediction()
Set the prediction array identifier.
- process()
Convert predictions into the final output.
Note
This class is abstract. Subclasses must implement the abstract methods. Once created, the values of its attributes cannot be changed.
- abstract enumerate_parameters() Iterable[dacapo.experiments.tasks.post_processors.post_processor_parameters.PostProcessorParameters]
Enumerate all possible parameters of this post-processor.
- Returns:
An iterable of PostProcessorParameters instances.
- Raises:
NotImplementedError – If the method is not implemented in the subclass.
Examples
>>> post_processor = MyPostProcessor() >>> for parameters in post_processor.enumerate_parameters(): ... print(parameters) MyPostProcessorParameters(param1=0.0, param2=0.0) MyPostProcessorParameters(param1=0.0, param2=1.0) MyPostProcessorParameters(param1=1.0, param2=0.0) MyPostProcessorParameters(param1=1.0, param2=1.0)
Note
This method must be implemented in the subclass. It should return an iterable of PostProcessorParameters instances.
- abstract set_prediction(prediction_array_identifier: dacapo.store.local_array_store.LocalArrayIdentifier) None
Set the prediction array identifier.
- Parameters:
prediction_array_identifier – The identifier of the array containing the model’s prediction.
- Raises:
NotImplementedError – If the method is not implemented in the subclass.
Examples
>>> post_processor = MyPostProcessor() >>> post_processor.set_prediction("prediction")
Note
This method must be implemented in the subclass. It should set the prediction_array_identifier attribute.
- abstract process(parameters: dacapo.experiments.tasks.post_processors.post_processor_parameters.PostProcessorParameters, output_array_identifier: dacapo.store.local_array_store.LocalArrayIdentifier, num_workers: int = 16, chunk_size: funlib.geometry.Coordinate = Coordinate((64, 64, 64))) dacapo.experiments.datasplits.datasets.arrays.Array
Convert predictions into the final output.
- Parameters:
parameters – The parameters of the post-processor.
output_array_identifier – The identifier of the array to store the output.
num_workers – The number of workers to use.
chunk_size – The size of the chunks to process.
- Returns:
The output array.
- Raises:
NotImplementedError – If the method is not implemented in the subclass.
Examples
>>> post_processor = MyPostProcessor() >>> post_processor.set_prediction("prediction") >>> parameters = MyPostProcessorParameters(param1=0.0, param2=0.0) >>> output = post_processor.process(parameters, "output")
Note
This method must be implemented in the subclass. It should convert the model’s prediction into the final output.
- class dacapo.experiments.tasks.post_processors.ThresholdPostProcessor
A post-processor that applies a threshold to the prediction.
- prediction_array_identifier
The identifier of the prediction array.
- prediction_array
The prediction array.
- enumerate_parameters()
Enumerate all possible parameters of this post-processor.
- set_prediction()
Set the prediction array.
- process()
Process the prediction with the given parameters.
Note
This post-processor applies a threshold to the prediction. The threshold is used to define the segmentation. The prediction array is set using the set_prediction method.
- enumerate_parameters() Iterable[dacapo.experiments.tasks.post_processors.threshold_post_processor_parameters.ThresholdPostProcessorParameters]
Enumerate all possible parameters of this post-processor.
- Returns:
A generator of parameters.
- Return type:
Generator[ThresholdPostProcessorParameters]
- Raises:
NotImplementedError – If the method is not implemented.
Examples
>>> for parameters in post_processor.enumerate_parameters(): ... print(parameters)
Note
This method should return a generator of instances of
ThresholdPostProcessorParameters.
- set_prediction(prediction_array_identifier)
Set the prediction array.
- Parameters:
prediction_array_identifier (LocalArrayIdentifier) – The identifier of the prediction array.
- Raises:
NotImplementedError – If the method is not implemented.
Examples
>>> post_processor.set_prediction(prediction_array_identifier)
Note
This method should set the prediction array using the given identifier.
- process(parameters: dacapo.experiments.tasks.post_processors.threshold_post_processor_parameters.ThresholdPostProcessorParameters, output_array_identifier: dacapo.store.array_store.LocalArrayIdentifier, num_workers: int = 12, block_size: daisy.Coordinate = Coordinate((256, 256, 256))) dacapo.experiments.datasplits.datasets.arrays.zarr_array.ZarrArray
Process the prediction with the given parameters.
- Parameters:
parameters (ThresholdPostProcessorParameters) – The parameters to use for processing.
output_array_identifier (LocalArrayIdentifier) – The identifier of the output array.
num_workers (int) – The number of workers to use for processing.
block_size (Coordinate) – The block size to use for processing.
- Returns:
The output array.
- Return type:
- Raises:
NotImplementedError – If the method is not implemented.
Examples
>>> post_processor.process(parameters, output_array_identifier)
Note
This method should process the prediction with the given parameters and return the output array. The method uses the run_blockwise function from the dacapo.blockwise.scheduler module to run the blockwise post-processing. The output array is created using the ZarrArray.create_from_array_identifier function from the dacapo.experiments.datasplits.datasets.arrays module.
- class dacapo.experiments.tasks.post_processors.ThresholdPostProcessorParameters
Parameters for the threshold post-processor. The threshold post-processor will set the output to 1 if the input is greater than the threshold, and 0 otherwise.
- threshold
The threshold value. If the input is greater than this value, the output will be set to 1. Otherwise, the output will be set to 0.
Note
This class is immutable. Once created, the values of its attributes cannot be changed.
- threshold: float
- class dacapo.experiments.tasks.post_processors.ArgmaxPostProcessor
Post-processor that takes the argmax of the input array along the channel axis. The output is a binary array where the value is 1 if the argmax is greater than the threshold, and 0 otherwise.
- prediction_array
The array containing the model’s prediction.
- enumerate_parameters()
Enumerate all possible parameters of this post-processor.
- set_prediction()
Set the prediction array identifier.
- process()
Convert predictions into the final output.
Note
This class is abstract. Subclasses must implement the abstract methods. Once created, the values of its attributes cannot be changed.
- enumerate_parameters()
Enumerate all possible parameters of this post-processor. Should return instances of
PostProcessorParameters.- Returns:
An iterable of PostProcessorParameters instances.
- Raises:
NotImplementedError – If the method is not implemented in the subclass.
Examples
>>> post_processor = ArgmaxPostProcessor() >>> for parameters in post_processor.enumerate_parameters(): ... print(parameters) ArgmaxPostProcessorParameters(id=0)
Note
This method must be implemented in the subclass. It should return an iterable of PostProcessorParameters instances.
- set_prediction(prediction_array_identifier)
Set the prediction array identifier.
- Parameters:
prediction_array_identifier – The identifier of the array containing the model’s prediction.
- Raises:
NotImplementedError – If the method is not implemented in the subclass.
Examples
>>> post_processor = ArgmaxPostProcessor() >>> post_processor.set_prediction("prediction")
Note
This method must be implemented in the subclass. It should set the prediction_array_identifier attribute.
- process(parameters, output_array_identifier: dacapo.store.array_store.LocalArrayIdentifier, num_workers: int = 16, block_size: daisy.Coordinate = Coordinate((256, 256, 256)))
Convert predictions into the final output.
- Parameters:
parameters – The parameters of the post-processor.
output_array_identifier – The identifier of the output array.
num_workers – The number of workers to use.
block_size – The size of the blocks to process.
- Returns:
The output array.
- Raises:
NotImplementedError – If the method is not implemented in the subclass.
Examples
>>> post_processor = ArgmaxPostProcessor() >>> post_processor.set_prediction("prediction") >>> post_processor.process(parameters, "output")
Note
This method must be implemented in the subclass. It should process the predictions and return the output array.
- class dacapo.experiments.tasks.post_processors.ArgmaxPostProcessorParameters
Parameters for the argmax post-processor. The argmax post-processor will set the output to the index of the maximum value in the input array.
- parameter_names()
Get the names of the parameters.
Note
This class is immutable. Once created, the values of its attributes cannot be changed.
- class dacapo.experiments.tasks.post_processors.WatershedPostProcessor(offsets: List[funlib.geometry.Coordinate])
A post-processor that applies a watershed transformation to the prediction.
- offsets
List of offsets for the watershed transformation.
- enumerate_parameters()
Enumerate all possible parameters of this post-processor.
- set_prediction()
Set the prediction array.
- process()
Process the prediction with the given parameters.
Note
This post-processor uses the watershed_function.py script to apply the watershed transformation. The offsets are used to define the neighborhood for the watershed transformation.
- offsets
- enumerate_parameters()
Enumerate all possible parameters of this post-processor. Should return instances of
PostProcessorParameters.- Returns:
A generator of parameters.
- Return type:
Generator[WatershedPostProcessorParameters]
- Raises:
NotImplementedError – If the method is not implemented.
Examples
>>> for parameters in post_processor.enumerate_parameters(): ... print(parameters)
Note
This method should be implemented by the subclass. It should return a generator of instances of
WatershedPostProcessorParameters.
- set_prediction(prediction_array_identifier)
Set the prediction array identifier.
- Parameters:
prediction_array_identifier – The identifier of the array containing the model’s prediction.
- Raises:
NotImplementedError – If the method is not implemented in the subclass.
Examples
>>> post_processor = MyPostProcessor() >>> post_processor.set_prediction("prediction")
Note
This method must be implemented in the subclass. It should set the prediction_array_identifier attribute.
- process(parameters: dacapo.experiments.tasks.post_processors.watershed_post_processor_parameters.WatershedPostProcessorParameters, output_array_identifier: dacapo.store.array_store.LocalArrayIdentifier, num_workers: int = 16, block_size: funlib.geometry.Coordinate = Coordinate((256, 256, 256)))
Process the prediction with the given parameters.
- Parameters:
parameters (WatershedPostProcessorParameters) – The parameters to use for processing.
output_array_identifier (LocalArrayIdentifier) – The output array identifier.
num_workers (int) – The number of workers to use for processing.
block_size (Coordinate) – The block size to use for processing.
- Returns:
The output array identifier.
- Return type:
- Raises:
NotImplementedError – If the method is not implemented.
Examples
>>> post_processor.process(parameters, output_array_identifier)
Note
This method should be implemented by the subclass. To run the watershed transformation, the method uses the segment_blockwise function from the dacapo.blockwise.scheduler module.
- class dacapo.experiments.tasks.post_processors.WatershedPostProcessorParameters
Parameters for the watershed post-processor.
- offsets
List of offsets for the watershed transformation.
- threshold
Threshold for the watershed transformation.
- sigma
Sigma for the watershed transformation.
- min_size
Minimum size of the segments.
- bias
Bias for the watershed transformation.
- context
Context for the watershed transformation.
Examples
>>> WatershedPostProcessorParameters(offsets=[(0, 0, 1), (0, 1, 0), (1, 0, 0)], threshold=0.5, sigma=1.0, min_size=100, bias=0.5, context=(32, 32, 32))
Note
This class is used by the
WatershedPostProcessorto define the parameters for the watershed transformation. The offsets are used to define the neighborhood for the watershed transformation.- bias: float
- context: funlib.geometry.Coordinate