2026-01-17 10:24:00 +01:00
|
|
|
# Dockerfile.gpu - CUDA-enabled PaddleOCR REST API
|
2026-01-17 10:46:36 +01:00
|
|
|
#
|
2026-01-17 11:10:13 +01:00
|
|
|
# Supports both architectures:
|
|
|
|
|
# - x86_64: Uses paddlepaddle-gpu from PaddlePaddle's CUDA index
|
|
|
|
|
# - ARM64: Uses local wheel from ./wheels/ (built on DGX Spark)
|
2026-01-17 10:46:36 +01:00
|
|
|
#
|
2026-01-17 11:10:13 +01:00
|
|
|
# For ARM64 (DGX Spark), first build the wheel:
|
|
|
|
|
# docker compose --profile build run --rm build-paddle
|
2026-01-17 10:46:36 +01:00
|
|
|
# Then build this image:
|
|
|
|
|
# docker compose build ocr-gpu
|
|
|
|
|
#
|
2026-01-17 11:10:13 +01:00
|
|
|
# For x86_64, just build directly (no wheel needed):
|
|
|
|
|
# docker compose build ocr-gpu
|
2026-01-17 10:24:00 +01:00
|
|
|
|
|
|
|
|
FROM nvidia/cuda:12.4.1-cudnn-runtime-ubuntu22.04
|
|
|
|
|
|
|
|
|
|
LABEL maintainer="Sergio Jimenez"
|
|
|
|
|
LABEL description="PaddleOCR Tuning REST API - GPU/CUDA version"
|
|
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
# Set environment variables
|
|
|
|
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
|
|
|
ENV PYTHONUNBUFFERED=1
|
|
|
|
|
ENV CUDA_VISIBLE_DEVICES=0
|
|
|
|
|
|
|
|
|
|
# Install Python 3.11 and system dependencies
|
|
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
|
|
|
python3.11 \
|
|
|
|
|
python3.11-venv \
|
|
|
|
|
python3-pip \
|
|
|
|
|
libgl1 \
|
|
|
|
|
libglib2.0-0 \
|
|
|
|
|
libsm6 \
|
|
|
|
|
libxext6 \
|
|
|
|
|
libxrender1 \
|
|
|
|
|
libgomp1 \
|
|
|
|
|
&& rm -rf /var/lib/apt/lists/* \
|
|
|
|
|
&& ln -sf /usr/bin/python3.11 /usr/bin/python
|
|
|
|
|
|
2026-01-17 11:10:13 +01:00
|
|
|
# Copy local wheels directory (may contain ARM64 wheel from build-paddle)
|
2026-01-17 10:46:36 +01:00
|
|
|
COPY wheels/ /tmp/wheels/
|
|
|
|
|
|
2026-01-17 11:10:13 +01:00
|
|
|
# Copy requirements
|
2026-01-17 10:24:00 +01:00
|
|
|
COPY requirements-gpu.txt .
|
2026-01-17 10:46:36 +01:00
|
|
|
|
2026-01-17 11:10:13 +01:00
|
|
|
# Install paddlepaddle: prefer local wheel (ARM64), fallback to CUDA index (x86_64)
|
2026-01-17 10:46:36 +01:00
|
|
|
RUN if ls /tmp/wheels/paddlepaddle*.whl 1>/dev/null 2>&1; then \
|
|
|
|
|
echo "=== Installing PaddlePaddle from local wheel (ARM64) ===" && \
|
|
|
|
|
pip install --no-cache-dir /tmp/wheels/paddlepaddle*.whl; \
|
|
|
|
|
else \
|
2026-01-17 11:10:13 +01:00
|
|
|
echo "=== Installing PaddlePaddle from CUDA index (x86_64) ===" && \
|
|
|
|
|
pip install --no-cache-dir paddlepaddle-gpu==3.2.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/; \
|
2026-01-17 10:46:36 +01:00
|
|
|
fi
|
|
|
|
|
|
2026-01-17 11:10:13 +01:00
|
|
|
# Install remaining dependencies (skip paddlepaddle-gpu line from requirements)
|
2026-01-17 10:46:36 +01:00
|
|
|
RUN grep -v "paddlepaddle-gpu" requirements-gpu.txt > /tmp/requirements-no-paddle.txt && \
|
2026-01-17 11:10:13 +01:00
|
|
|
pip install --no-cache-dir -r /tmp/requirements-no-paddle.txt && \
|
|
|
|
|
rm -rf /tmp/wheels /tmp/requirements-no-paddle.txt
|
2026-01-17 10:24:00 +01:00
|
|
|
|
|
|
|
|
# Copy application code
|
|
|
|
|
COPY paddle_ocr_tuning_rest.py .
|
|
|
|
|
COPY dataset_manager.py .
|
|
|
|
|
|
|
|
|
|
# Build arguments for models to bake into image
|
|
|
|
|
ARG DET_MODEL=PP-OCRv5_server_det
|
|
|
|
|
ARG REC_MODEL=PP-OCRv5_server_rec
|
|
|
|
|
|
|
|
|
|
# Set as environment variables (can be overridden at runtime)
|
|
|
|
|
ENV PADDLE_DET_MODEL=${DET_MODEL}
|
|
|
|
|
ENV PADDLE_REC_MODEL=${REC_MODEL}
|
|
|
|
|
|
|
|
|
|
# Download models during build (not at runtime)
|
|
|
|
|
RUN python -c "\
|
|
|
|
|
import os; \
|
|
|
|
|
from paddleocr import PaddleOCR; \
|
|
|
|
|
det = os.environ.get('PADDLE_DET_MODEL', 'PP-OCRv5_server_det'); \
|
|
|
|
|
rec = os.environ.get('PADDLE_REC_MODEL', 'PP-OCRv5_server_rec'); \
|
|
|
|
|
print(f'Downloading models: det={det}, rec={rec}'); \
|
|
|
|
|
ocr = PaddleOCR(text_detection_model_name=det, text_recognition_model_name=rec); \
|
|
|
|
|
print('Models downloaded successfully!')"
|
|
|
|
|
|
|
|
|
|
# Volume for dataset and optional additional model cache
|
|
|
|
|
VOLUME ["/app/dataset", "/root/.paddlex"]
|
|
|
|
|
|
|
|
|
|
# Expose API port
|
|
|
|
|
EXPOSE 8000
|
|
|
|
|
|
|
|
|
|
# Health check
|
|
|
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
|
|
|
|
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1
|
|
|
|
|
|
|
|
|
|
# Run the API server
|
|
|
|
|
CMD ["uvicorn", "paddle_ocr_tuning_rest:app", "--host", "0.0.0.0", "--port", "8000"]
|