How project-monai/monailabel works
Project Type and Purpose
• This is a Python-based server–client framework for AI-assisted interactive medical image annotation.
• The “MONAI Label Server” exposes REST endpoints; “Clients” include CLI tools and viewer plugins (3D Slicer, OHIF, QuPath, CVAT, DSA, etc.).
• Core functionality: load medical images, run inference/training tasks in response to user interactions, and store results back to datastores.
File Structure
• Top-level “monailabel” package:
• app.py / main.py – server bootstrap and FastAPI (Starlette) app
• endpoints/ – one module per REST route (infer, train, active learning, login, logs, proxy, etc.)
• interfaces/ – abstract interfaces for tasks, datastores, utils
• tasks/ – implementations of inference, training, scoring, active‐learning pipelines
• datastore/ – adapters for Local FS, DICOMWeb, CVAT, DSA, XNAT, plus helpers to convert and colorize
• utils/ – session management, asynchronous helper, transform pipelines
• “plugins/” directory: viewer-specific integration modules (OHIF, Slicer, QuPath, CVAT, etc.)
• “sample-apps/”: prebuilt app definitions (radiology, pathology, endoscopy, monaibundle) that load configs, model bundles, transforms.
• tests/ and docs/ indicate a CI/CD pipeline and extensive coverage.
README for Additional Insights
• The README describes a server–client model, lists supported viewers and datastores, and enumerates core features: interactive tools (DeepEdit, DeepGrow, SAM 2.0), active learning, model bundles.
• It clarifies that server and client can run on separate machines, communicating over HTTP/DICOMWeb.
• Clients / Viewers (purple):
– CLI client (monailabel client.py)
– Viewer plugins (OHIF, QuPath, 3DSlicer, CVAT, DSA, MITK)
• MONAI Label Server (blue):
– API Layer (FastAPI/Starlette + endpoint modules)
– Orchestration Layer (interfaces + task handlers)
– ML Engine (MONAI models, SAM 2D/3D, active learning logic)
– Utilities (async task manager, transforms, logging, sessions)
• Datastores (orange):
– Local filesystem (NIfTI, NRRD, TIFF, SVS, video frames + “labels/final”)
– DICOMWeb / PACS
– External annotation stores (CVAT, DSA, XNAT)
• Model Zoo / Bundles (green):
– Pretrained segmentation models, DeepEdit/DNN architecture, monaibundle archives
• External Services (red):
– DICOMWeb server, Authentication provider (if used), Database (optional for sessions/logs)
1. Client → Server (HTTP REST calls: /infer, /train, /activelearning)
2. API Layer → Orchestration Layer (delegates to interfaces/task modules)
3. Task module → Datastore adapter (load images, labels)
4. Task module → ML Engine (run inference/training)
5. ML Engine → Datastore adapter (write back predictions/metrics)
6. Task module → Async Task Manager (for long-running jobs)
7. Async Task Manager → Notification channel (polling or WebSocket updates)
8. Server ↔ External DICOMWeb / PACS (when configured)
c. Architectural Patterns & Principles:
• Layered architecture: clear separation between API, business logic (task handlers), and data layer (datastore).
• Plugin/Adapter pattern: viewer integrations and datastore connectors are pluggable modules.
• Dependency injection via configuration—apps load only required models, datastores, tasks.
• Asynchronous processing for heavy compute/training tasks.
d. Key Technologies & Libraries:
• Python 3.8+; FastAPI (Starlette) for REST
• Pydantic for request/response models
• MONAI for deep learning models, transforms
• PyTorch or TensorFlow backends (depending on sample app)
• Docker for containerized deployment
• CUCIM/CuPy optional GPU acceleration
• Third-party viewers use REST or DICOMWeb clients