Project 3: Deploy a Deep Learning Model
End-to-end project: train a deep learning model, build a FastAPI service, containerize with Docker, and deploy to cloud infrastructure.
Project Architecture
Phase 1: Model Training
Phase 2: Export Model
Phase 3: FastAPI Server
Phase 4: Docker Build
FROM python:3.11-slim AS builder
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
RUN python export_model.py
FROM python:3.11-slim
WORKDIR /app
COPY --from=builder /app/model.pt .
COPY --from=builder /app/app.py .
COPY --from=builder /app/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 8000
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "2"]
Phase 5: Cloud Deploy
# AWS ECS Task Definition
{
"family": "dl-model-service",
"networkMode": "awsvpc",
"requiresCompatibilities": ["FARGATE"],
"cpu": "1024",
"memory": "2048",
"containerDefinitions": [{
"name": "model-api",
"image": "123456789.dkr.ecr.us-east-1.amazonaws.com/dl-model:latest",
"portMappings": [{"containerPort": 8000, "protocol": "tcp"}],
"healthCheck": {
"command": ["CMD-SHELL", "curl -f http://localhost:8000/health || exit 1"],
"interval": 30
}
}]
}
Evaluation Criteria
- Model accuracy meets threshold
- Inference latency under 100ms (p95)
- API handles 100+ concurrent requests
- Docker image under 1GB
- Health checks pass consistently
- Monitoring dashboards operational
Key Takeaways
- TorchScript/ONNX: Export models for production inference
- Multi-stage Docker: Minimize image size
- Async API: Handle concurrent requests efficiently
- Health checks: Enable orchestrator-managed deployments