Paddle ocr gpu support. #4

Merged
Seryusjj merged 40 commits from gpu_support into main 2026-01-19 17:35:25 +00:00
4 changed files with 134 additions and 24 deletions
Showing only changes of commit a07d89ce21 - Show all commits

View File

@@ -35,20 +35,15 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& ln -sf /usr/bin/python3.12 /usr/bin/python
# Install PyTorch with CUDA support
# cu128 index has both amd64 and arm64 wheels
RUN python -m pip install --no-cache-dir \
# Copy requirements first for better caching
COPY requirements.txt .
# Install PyTorch with CUDA support first (cu128 index has amd64 + arm64 wheels)
RUN python -m pip install --no-cache-dir --break-system-packages \
torch torchvision --index-url https://download.pytorch.org/whl/cu128
# Install DocTR and other dependencies
RUN python -m pip install --no-cache-dir \
"python-doctr[torch]>=0.8.0" \
fastapi>=0.104.0 \
"uvicorn[standard]" \
pydantic>=2.0.0 \
jiwer>=3.0.0 \
numpy>=1.24.0 \
pillow>=10.0.0
# Install remaining dependencies from requirements.txt (skip torch, already installed)
RUN grep -v "^torch" requirements.txt | python -m pip install --no-cache-dir --break-system-packages -r /dev/stdin
# Copy application code
COPY doctr_tuning_rest.py .

View File

@@ -0,0 +1,61 @@
# docker-compose.yml - DocTR REST API
# Usage:
# CPU: docker compose up ocr-cpu
# GPU: docker compose up ocr-gpu
#
# Port: 8003
services:
# CPU-only service
ocr-cpu:
image: seryus.ddns.net/unir/doctr-cpu:latest
container_name: doctr-cpu
ports:
- "8003:8000"
volumes:
- ../dataset:/app/dataset:ro
- doctr-cache:/root/.cache/doctr
environment:
- PYTHONUNBUFFERED=1
- DOCTR_DET_ARCH=db_resnet50
- DOCTR_RECO_ARCH=crnn_vgg16_bn
restart: unless-stopped
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"]
interval: 30s
timeout: 10s
retries: 3
start_period: 180s
# GPU service (requires NVIDIA Container Toolkit)
ocr-gpu:
image: seryus.ddns.net/unir/doctr-gpu:latest
container_name: doctr-gpu
ports:
- "8003:8000"
volumes:
- ../dataset:/app/dataset:ro
- doctr-cache:/root/.cache/doctr
environment:
- PYTHONUNBUFFERED=1
- CUDA_VISIBLE_DEVICES=0
- DOCTR_DET_ARCH=db_resnet50
- DOCTR_RECO_ARCH=crnn_vgg16_bn
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
restart: unless-stopped
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"]
interval: 30s
timeout: 10s
retries: 3
start_period: 180s
volumes:
doctr-cache:
name: doctr-model-cache

View File

@@ -34,20 +34,15 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& ln -sf /usr/bin/python3.12 /usr/bin/python
# Install PyTorch with CUDA support
# cu128 index has both amd64 and arm64 wheels
RUN python -m pip install --no-cache-dir \
# Copy requirements first for better caching
COPY requirements.txt .
# Install PyTorch with CUDA support first (cu128 index has amd64 + arm64 wheels)
RUN python -m pip install --no-cache-dir --break-system-packages \
torch torchvision --index-url https://download.pytorch.org/whl/cu128
# Install EasyOCR and other dependencies
RUN python -m pip install --no-cache-dir \
easyocr>=1.7.0 \
fastapi>=0.104.0 \
"uvicorn[standard]" \
pydantic>=2.0.0 \
jiwer>=3.0.0 \
numpy>=1.24.0 \
pillow>=10.0.0
# Install remaining dependencies from requirements.txt (skip torch, already installed)
RUN grep -v "^torch" requirements.txt | python -m pip install --no-cache-dir --break-system-packages -r /dev/stdin
# Copy application code
COPY easyocr_tuning_rest.py .

View File

@@ -0,0 +1,59 @@
# docker-compose.yml - EasyOCR REST API
# Usage:
# CPU: docker compose up ocr-cpu
# GPU: docker compose up ocr-gpu
#
# Port: 8002
services:
# CPU-only service
ocr-cpu:
image: seryus.ddns.net/unir/easyocr-cpu:latest
container_name: easyocr-cpu
ports:
- "8002:8000"
volumes:
- ../dataset:/app/dataset:ro
- easyocr-cache:/root/.EasyOCR
environment:
- PYTHONUNBUFFERED=1
- EASYOCR_LANGUAGES=es,en
restart: unless-stopped
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"]
interval: 30s
timeout: 10s
retries: 3
start_period: 120s
# GPU service (requires NVIDIA Container Toolkit)
ocr-gpu:
image: seryus.ddns.net/unir/easyocr-gpu:latest
container_name: easyocr-gpu
ports:
- "8002:8000"
volumes:
- ../dataset:/app/dataset:ro
- easyocr-cache:/root/.EasyOCR
environment:
- PYTHONUNBUFFERED=1
- CUDA_VISIBLE_DEVICES=0
- EASYOCR_LANGUAGES=es,en
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
restart: unless-stopped
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"]
interval: 30s
timeout: 10s
retries: 3
start_period: 120s
volumes:
easyocr-cache:
name: easyocr-model-cache