Skip to content

prediction_worker

A thread worker function running CAREamics prediction.

predict_worker(careamist, pred_data, configuration, update_queue) #

Model prediction worker.

Parameters:

Name Type Description Default
careamist CAREamist

CAREamist instance.

required
pred_data NDArray | str

Prediction data source.

required
configuration BaseConfig

careamics configuration.

required
update_queue Queue

Queue used to send updates to the UI.

required

Yields:

Type Description
Generator[PredictionUpdate, None, None]

Updates.

Source code in src/careamics_napari/workers/prediction_worker.py
@thread_worker
def predict_worker(
    careamist: CAREamist,
    pred_data: NDArray | str,
    configuration: BaseConfig,
    update_queue: Queue,
) -> Generator[PredictionUpdate, None, None]:
    """Model prediction worker.

    Parameters
    ----------
    careamist : CAREamist
        CAREamist instance.
    pred_data : NDArray | str
        Prediction data source.
    configuration : BaseConfig
        careamics configuration.
    update_queue : Queue
        Queue used to send updates to the UI.

    Yields
    ------
    Generator[PredictionUpdate, None, None]
        Updates.
    """
    # start prediction thread
    prediction = Thread(
        target=_predict,
        args=(
            careamist,
            pred_data,
            configuration,
            update_queue,
        ),
    )
    prediction.start()

    # look for updates
    while True:
        update: PredictionUpdate = update_queue.get(block=True)

        yield update

        if (
            update.type == PredictionUpdateType.STATE
            or update.type == PredictionUpdateType.EXCEPTION
        ):
            break