dacapo.apply

Attributes

logger

Functions

apply(run_name, input_container, input_dataset, ...[, ...])

Load weights and apply a trained model to a dataset. If iteration is None, the best iteration based on the criterion is used. If roi is None, the whole input dataset is used.

apply_run(run, iteration, parameters, ...[, roi, ...])

Apply the model to a dataset. If roi is None, the whole input dataset is used. Assumes model is already loaded.

Module Contents

dacapo.apply.logger
dacapo.apply.apply(run_name: str, input_container: upath.UPath | str, input_dataset: str, output_path: upath.UPath | str, validation_dataset: dacapo.experiments.datasplits.datasets.dataset.Dataset | str | None = None, criterion: str = 'voi', iteration: int | None = None, parameters: dacapo.experiments.tasks.post_processors.post_processor_parameters.PostProcessorParameters | str | None = None, roi: funlib.geometry.Roi | str | None = None, num_workers: int = 12, output_dtype: numpy.dtype | str = np.uint8, overwrite: bool = True, file_format: str = 'zarr')

Load weights and apply a trained model to a dataset. If iteration is None, the best iteration based on the criterion is used. If roi is None, the whole input dataset is used.

Parameters:
  • run_name (str) – Name of the run to apply.

  • input_container (Path | str) – Path to the input container.

  • input_dataset (str) – Name of the input dataset.

  • output_path (Path | str) – Path to the output container.

  • validation_dataset (Optional[Dataset | str], optional) – Validation dataset to use for finding the best parameters. Defaults to None.

  • criterion (str, optional) – Criterion to use for finding the best parameters. Defaults to “voi”.

  • iteration (Optional[int], optional) – Iteration to use. If None, the best iteration is used. Defaults to None.

  • parameters (Optional[PostProcessorParameters | str], optional) – Post-processor parameters to use. If None, the best parameters are found. Defaults to None.

  • roi (Optional[Roi | str], optional) – Region of interest to use. If None, the whole input dataset is used. Defaults to None.

  • num_workers (int, optional) – Number of workers to use. Defaults to 12.

  • output_dtype (np.dtype | str, optional) – Output dtype. Defaults to np.uint8.

  • overwrite (bool, optional) – Overwrite existing output. Defaults to True.

  • file_format (str, optional) – File format to use. Defaults to “zarr”.

Raises:
  • ValueError – If validation_dataset is None and criterion is not None.

  • ValueError – If parameters is a string that cannot be parsed to PostProcessorParameters.

  • ValueError – If parameters is not a PostProcessorParameters object.

Examples

>>> apply(
...     run_name="run_1",
...     input_container="data.zarr",
...     input_dataset="raw",
...     output_path="output.zarr",
...     validation_dataset="validate",
...     criterion="voi",
...     num_workers=12,
...     output_dtype=np.uint8,
...     overwrite=True,
... )
dacapo.apply.apply_run(run: dacapo.experiments.run.Run, iteration: int, parameters: dacapo.experiments.tasks.post_processors.post_processor_parameters.PostProcessorParameters, input_array_identifier: dacapo.store.array_store.LocalArrayIdentifier, prediction_array_identifier: dacapo.store.array_store.LocalArrayIdentifier, output_array_identifier: dacapo.store.array_store.LocalArrayIdentifier, roi: funlib.geometry.Roi | None = None, num_workers: int = 12, output_dtype: numpy.dtype | str = np.uint8, overwrite: bool = True)

Apply the model to a dataset. If roi is None, the whole input dataset is used. Assumes model is already loaded.

Parameters:
  • run (Run) – The run object containing the task and post-processor.

  • iteration (int) – The iteration number.

  • parameters (PostProcessorParameters) – The post-processor parameters.

  • input_array_identifier (LocalArrayIdentifier) – The identifier for the input array.

  • prediction_array_identifier (LocalArrayIdentifier) – The identifier for the prediction array.

  • output_array_identifier (LocalArrayIdentifier) – The identifier for the output array.

  • roi (Optional[Roi], optional) – The region of interest. Defaults to None.

  • num_workers (int, optional) – The number of workers for parallel processing. Defaults to 12.

  • output_dtype (np.dtype | str, optional) – The output data type. Defaults to np.uint8.

  • overwrite (bool, optional) – Whether to overwrite existing output. Defaults to True.

Raises:

ValueError – If the input array is not a ZarrArray.

Examples

>>> apply_run(
...     run=run,
...     iteration=1,
...     parameters=parameters,
...     input_array_identifier=LocalArrayIdentifier(Path("data.zarr"), "raw"),
...     prediction_array_identifier=LocalArrayIdentifier(Path("output.zarr"), "prediction_run_1_1"),
...     output_array_identifier=LocalArrayIdentifier(Path("output.zarr"), "output_run_1_1"),
...     roi=None,
...     num_workers=12,
...     output_dtype=np.uint8,
...     overwrite=True,
... )