Skip to content

prediction_worker

A thread worker function running CAREamics prediction.

predict_worker(careamist, config_signal, update_queue) #

Model prediction worker.

Parameters:

Name Type Description Default
careamist CAREamist

CAREamist instance.

required
config_signal PredictionSignal

Prediction signal.

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,
    config_signal: PredictionSignal,
    update_queue: Queue,
) -> Generator[PredictionUpdate, None, None]:
    """Model prediction worker.

    Parameters
    ----------
    careamist : CAREamist
        CAREamist instance.
    config_signal : PredictionSignal
        Prediction signal.
    update_queue : Queue
        Queue used to send updates to the UI.

    Yields
    ------
    Generator[PredictionUpdate, None, None]
        Updates.
    """
    # start training thread
    training = Thread(
        target=_predict,
        args=(
            careamist,
            config_signal,
            update_queue,
        ),
    )
    training.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