Getting Started
Note: All
http://localhostURLs in this documentation refer to the local development server and are not exposed to the public internet.
This guide walks you through setting up and running the MedML Training Dashboard — a FastAPI web application for managing medical image classification and segmentation workflows on AWS.
Prerequisites
Before you begin, ensure you have the following:
Requirement |
Details |
|---|---|
Python |
3.11 or higher |
AWS Account |
With permissions for S3, SageMaker, and ECR |
AWS CLI |
Installed and configured ( |
Docker |
Optional — required only for the multi-service setup (dashboard + MLflow + TensorBoard) |
Git |
For cloning the repository |
AWS Permissions
Your AWS credentials need access to:
S3 — read/write for training data, model artifacts, and capture logs
SageMaker — create/manage training jobs, endpoints, processing jobs, and monitoring schedules
ECR — pull/push Docker images (only needed if building custom training containers)
⚠️ Medical AI Safety Notice
This platform is designed for research and development purposes only.
Models trained and deployed through this system are not validated for clinical use. Production deployment of medical imaging AI requires:
Regulatory clearance — FDA 510(k), De Novo, PMA, CE marking, or equivalent regulatory pathway for your jurisdiction
Clinical validation studies — Prospective trials demonstrating safety and efficacy on the target patient population
Human-in-the-loop oversight — Qualified healthcare professionals must review and interpret all AI predictions
Bias and fairness evaluation — Subgroup analysis across demographic groups to ensure equitable performance
Continuous monitoring — Post-deployment surveillance for model drift and performance degradation
AI predictions must not be used as the sole basis for medical decisions.
Consult with regulatory affairs, clinical validation teams, and your institution’s IRB/ethics board before any patient-facing deployment. For guidance on responsible AI practices in healthcare, see the AWS Responsible AI documentation and AWS Healthcare AI compliance resources.
Installation
1. Clone the repository
git clone <repository-url>
cd Kiro-ML-model
2. Create a virtual environment
python3 -m venv .venv
source .venv/bin/activate
3. Install dependencies
pip install -r requirements.txt
This installs FastAPI, boto3, PyTorch, MONAI, MLflow, and all other required packages.
4. Copy environment files
cp .env.example .env
cp .env.local.example .env.local
Edit both files with your configuration (see Configuration below).
Quick Setup
Once .env.local is configured with your AWS_ACCOUNT_ID, run the setup script to create the SageMaker IAM role and build/push all Docker images in one step:
./setup.sh
Or run individual steps:
./setup.sh --role # Only create the SageMaker execution role
./setup.sh --images # Only build and push Docker images
The role creation script (create-sagemaker-role.sh) mirrors the Python get_or_create_role() utility from utils.py. It creates a role named AmazonSageMaker-ExecutionRole-sgm with the same managed policies and inline MLflow policy, so the behavior is identical whether you run the bash script or use the Python helper in notebooks.
# Equivalent standalone usage:
./create-sagemaker-role.sh # Uses default name
./create-sagemaker-role.sh MyCustomRoleName # Custom name
The setup script reads all account-specific values from .env.local — no positional arguments needed.
Configuration
The application loads environment variables in two layers:
.env— General application configuration (loaded first).env.local— Account-specific overrides (loaded second, takes priority)
.env.local is gitignored and should never be committed — it contains your AWS account-specific values.
.env — General config
Variable |
Description |
Default |
|---|---|---|
|
AWS access key (optional if using |
— |
|
AWS secret key (optional if using |
— |
|
AWS region for all services |
|
|
MLflow server URI for experiment tracking |
|
|
Default MLflow experiment name |
|
|
Directory for TensorBoard log files |
|
.env.local — Account-specific config
Variable |
Description |
Example |
|---|---|---|
|
Your 12-digit AWS account ID |
|
|
IAM role ARN that SageMaker assumes for training and deployment |
|
|
ECR URI for the classification training container |
|
|
ECR URI for the segmentation training container |
|
|
ECR URI for the classification inference container |
|
|
ECR URI for the segmentation inference container |
|
|
Default S3 URI for training data (pre-populates the UI form) |
|
|
S3 URI of a test DICOM image for integration tests |
|
|
S3 URI of a test NIfTI volume for segmentation tests |
|
Tip: You only need
AWS_ACCOUNT_IDandSAGEMAKER_ROLE_ARNto get started. The ECR image URIs are required when launching SageMaker training jobs or deploying endpoints.
First Launch
Start the application:
python main.py
The dashboard starts at http://localhost:8000.
Open it in your browser — you’ll see the main dashboard with tabs for Training, Deployment, Inference, Monitoring, and more.
On first launch with empty data stores, the local job and deployment lists will be empty. See the Initial Setup section below to populate them from AWS.
Initial Setup
Option A: Configure AWS via environment variables
If your .env or ~/.aws/credentials already has valid AWS credentials, the app connects automatically on startup.
Option B: Configure AWS via the UI
Open http://localhost:8000
Navigate to the AWS section
Enter your Access Key ID, Secret Access Key, and Region
Click Connect
Sync existing resources from AWS
Once connected, pull your existing SageMaker resources into the dashboard:
Go to the Training tab → click Sync from AWS to import existing training jobs
Go to the Deployment tab → click Sync from AWS to import existing endpoints
Go to the Evaluation tab → click Sync from AWS to import existing evaluation jobs
This populates the local data stores (data/sagemaker_jobs.json, data/deployments.json) so subsequent loads are fast and don’t require AWS calls.
Docker Setup
For a full development environment with MLflow and TensorBoard, use Docker Compose:
docker-compose up --build
This starts three services:
Service |
URL |
Purpose |
|---|---|---|
Dashboard |
http://localhost:8000 |
Main application UI and API |
MLflow |
http://localhost:5000 |
Experiment tracking and model registry |
TensorBoard |
http://localhost:6006 |
Training visualization |
Alternatively, use the startup script to run all services without Docker:
chmod +x start.sh
./start.sh
This starts MLflow, TensorBoard, and the FastAPI app together in the background.
Quick Start Workflow
Here’s a complete end-to-end workflow: connect to AWS, prepare data, train a model, deploy it, and run inference.
Step 1 — Connect to AWS
Ensure your AWS credentials are configured (via .env, environment variables, or the UI). Verify the connection by browsing S3 buckets in the AWS tab.
Step 2 — Prepare training data in S3
Upload your medical imaging dataset to S3 in the expected folder structure:
s3://your-bucket/training-data/
├── class_a/
│ ├── image001.dcm
│ ├── image002.dcm
│ └── ...
├── class_b/
│ ├── image003.dcm
│ └── ...
└── class_c/
└── ...
Each subfolder name becomes a class label. The number of classes is determined automatically from the folder structure.
For segmentation tasks, organize data with paired images and labels.
Step 3 — Train a model
Option A: SageMaker training (recommended for GPU workloads)
Go to the Training tab
Select SageMaker Training
Configure:
Model architecture — ResNet50, VGG16, EfficientNet, DenseNet121, ViT, or custom
Data S3 URI — path to your training data (pre-filled from
DEFAULT_DATA_S3_URI)Instance type — e.g.
ml.g5.xlargefor GPU trainingEpochs, learning rate, batch size — training hyperparameters
MLflow tracking URI — optional, for experiment tracking
Click Start Training
The job runs on SageMaker. Monitor progress in the Training tab — active jobs auto-refresh their status.
Option B: Local training
Select Local Training in the Training tab
Choose your model and dataset
Training runs on your local machine with MLflow and TensorBoard tracking
Step 4 — Deploy the model
Once training completes:
Go to the Deployment tab
Click Deploy on a completed training job, or create a new deployment:
Endpoint type — choose Real-time or Async (radio buttons)
Model artifacts — S3 URI of the
model.tar.gzproduced by trainingInference image — ECR URI of the inference container (from
.env.local)Instance type — e.g.
ml.g5.xlargeRole ARN — SageMaker execution role (from
.env.local)Output S3 URI — S3 prefix for inference results (required for async, optional for real-time)
Click Deploy
The endpoint progresses from Creating → InService. This typically takes 5–10 minutes.
Once deployed, endpoint cards display scaling controls: Scale up (+), Scale down (-), and Scale to 0 (async only — real-time endpoints require a minimum of 1 instance). An active endpoint count badge shows endpoint names and instance counts at a glance.
Step 5 — Run inference
Once the endpoint is InService:
Go to the Inference tab
Select the endpoint and task type (classification or segmentation)
Provide input:
S3 URI — point to an image in S3
File upload — upload a DICOM or NIfTI file directly from your browser
Click Invoke
The response shows predicted classes with confidence scores (classification) or a binary mask with volume statistics (segmentation).
Step 6 — Monitor (optional)
Set up Model Monitor to track prediction drift:
Enable Data Capture on the endpoint (Monitoring tab → Data Capture)
Run a Baseline job against your training data
Create a Monitoring Schedule to compare live traffic against the baseline
Next Steps
Evaluation — run a SageMaker Processing Job to evaluate endpoint accuracy on a labeled test set
Fairness Analysis — scan DICOM metadata for demographic distributions and bias auditing
Fine-tuning — resume training from a checkpoint using
checkpoint_s3_uriReport Generation — generate academic paper sections from completed training and evaluation jobs
Custom Containers — build and push BYOC training/inference images (see README for
build_and_push.shinstructions)
Troubleshooting
Issue |
Solution |
|---|---|
|
Set credentials in |
SageMaker job fails immediately |
Check that |
Endpoint stuck in |
Wait up to 10 minutes; check the SageMaker console for errors |
MLflow not tracking |
Ensure |
Docker build fails with |
Run |
SageMaker rejects image with |
Your Docker image was built in OCI format. Rebuild with |
Real-time endpoint times out on first request |
This is a cold start — the model loads into GPU memory on the first invocation. The first request may exceed the 60s API gateway timeout, but subsequent requests are fast (<30s). Send a warm-up request after deployment, or use async endpoints for segmentation which have no timeout limit |
Real-time works on second request but not first |
Cold start. The model and MONAI transforms are initialized on the first |
Empty job list after restart |
Data stores auto-rebuild from |