Skip to main content

Inference Service

A simple REST API that triggers Argo Workflows for model inference on vxData resources. Results are written back to vxData automatically.

API: https://inference.fra.virdx.dev/

How it works

User hits POST https://inference.fra.virdx.dev/<service>
->
Argo workflow is launched
->
Workflow image pulls specified resources from vxData, runs inference, uploads results back to vxData
->
User can retrieve results from vxData

Repo structure

  1. A FastAPI service that triggers Argo workflows for desired computations
  2. A Docker image bundling all relevant repos (viseg, histo, vxdata-sdk, ...) for Argo-workflow-based inference jobs
  3. A Python package (virdx-inference) for Python-based requests to the REST API

Usage

RESTPOST /viseg, /histo-preprocessing, /diffsim with a JSON body matching the schema below.

curl -X POST https://inference.fra.virdx.dev/histo-preprocessing \
-H 'Content-Type: application/json' \
-d '{
"input_resources": ["histo-scan/abc123"],
"tissue_detection_mag": 5.0,
"stats_level": 2,
"output_level": 0,
"crop_margin_frac": 0.05,
"tissue_detection_params": {
"min_component_area": 200000,
"fill_border_holes": false
},
"cpu": 8,
"memory": "32Gi",
"gpu": 0
}'

Python client:

pixi add virdx-inference
from inference.client import submit, VisegInference

job_id = submit(VisegInference(input_resources=["volume/abc123"]))

Supported services

All services share these base fields from InferenceRequest:

ParameterDefaultDescription
input_resourcesList of vxData resource identifiers (required)
vxdata_api_url"https://data.fra.virdx.dev/"vxData API endpoint
cpu4CPU cores allocated to the Argo workflow pod
gpu1GPUs allocated to the Argo workflow pod
memory"16Gi"Memory allocated to the Argo workflow pod

Full parameter schemas: src/inference/schemas/__init__.py

viseg

Anatomy segmentation on Volume resources.

ParameterDefaultDescription
model_id"DEFAULT"Viseg model; DEFAULT resolves to the latest recommended model
compute_uncertainty_scorefalseRun uncertainty estimation (logged only, not stored)
batch_size4Inference batch size passed to viseg

histo-preprocessing

Preprocessing pipeline for HistoScan resources.

ParameterDefaultDescription
tissue_detection_mag5.0Magnification level for tissue detection
stats_level2Pyramid level at which output statistics are computed
output_level0Pyramid level for image and label masks (0 = native resolution)
crop_margin_frac0.05Fractional margin added around the detected tissue crop
tissue_detection_params(see below)Fine-grained tissue detection parameters

tissue_detection_params (HistoTissueDetectionParams):

ParameterDefaultDescription
thresholdnull
blur_ksize7
early_dilate_ksize51
early_dilate_iters5
early_erode_ksizenull
early_erode_itersnull
pad10
min_raw_area20000
dilate_ksize51
dilate_iters6
erode_ksizenull
erode_itersnull
close_ksize101
fill_border_holestrue
max_border_fraction0.1
min_component_area100000
min_area_frac_of_largest0.0

diffsim

Diffsim simulations on HistoMap resources of type == "DOMAIN_REPRESENTATION".

ParameterDefaultDescription
protocol"bpmri"Simulation protocol acting as a map to more complex protocol definition, we currently only allow dummy bpmri value
walkers_count10000000Number of random walkers
voxel_resolution1e-3MRI voxel resolution in metres (e.g. 1e-3 = 1 mm)

Planned services

  • histo-domain-representation — schema stub exists; implementation pending v5 pipeline.
  • ve2e — specify model and inference task, pass in patient(s). Will collect task-specific inference data, load model, perform inference, store predictions to vxData. Nice for benchmarking!

Deployment

  1. Build the API and inference images: bash deployments/build.sh
  2. Trigger Argo CD to pick up the new image and re-deploy the API.
  3. Any newly submitted inference request workflow will automatically use the latest inference image.

Future ideas

  • Endpoint for querying status and logs of jobs
  • Endpoint for retrieving identifiers of produced resources
  • Validation of input resources on API side (instead of only failing in the workflow)