File size: 4,145 Bytes
2b7aae2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# STARRY Python ML Services Dockerfile
# Multi-stage build for PyTorch + TensorFlow services

# ============================================================
# Stage 1: Base image with CUDA support
# ============================================================
# Use CUDA 12.1 runtime - PyTorch wheel includes cudnn
FROM nvidia/cuda:12.1.0-runtime-ubuntu22.04 AS base

ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1

# Install system dependencies
RUN apt-get update && apt-get install -y \
    python3.11 \
    python3.11-dev \
    python3-pip \
    libgl1-mesa-glx \
    libglib2.0-0 \
    libsm6 \
    libxext6 \
    libxrender-dev \
    git \
    && rm -rf /var/lib/apt/lists/*

# Set Python 3.11 as default
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1 \
    && update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1

# Upgrade pip
RUN python -m pip install --upgrade pip

# ============================================================
# Stage 2: PyTorch services (layout, mask, semantic, gauge, loc)
# ============================================================
FROM base AS pytorch-services

WORKDIR /app

# Install PyTorch with CUDA support
# Using cu121 for compatibility with CUDA driver 12.4
RUN pip install --no-cache-dir \
    "numpy>=1.26.0,<2.0.0" \
    torch==2.5.1 \
    torchvision==0.20.1 \
    --index-url https://download.pytorch.org/whl/cu121

# Install common dependencies
RUN pip install --no-cache-dir \
    "opencv-python-headless<4.11" \
    Pillow>=8.0.0 \
    PyYAML>=5.4.0 \
    pyzmq>=22.0.0 \
    msgpack>=1.0.0 \
    dill \
    scipy \
    imgaug \
    scikit-image \
    python-dotenv \
    fs \
    tqdm \
    einops \
    lmdb

# Source code should be mounted as volume at runtime:
# -v /path/to/deep-starry:/app/deep-starry:ro
ENV PYTHONPATH=/app/deep-starry

# Default command (override with docker-compose)
CMD ["python", "--help"]


# ============================================================
# Stage 3: TensorFlow services (ocr, brackets)
# ============================================================
FROM base AS tensorflow-services

WORKDIR /app

# Install TensorFlow with legacy Keras support
RUN pip install --no-cache-dir \
    "numpy==1.26.4" \
    tensorflow==2.20.0 \
    tf_keras==2.20.1 \
    "opencv-python-headless<4.11" \
    Pillow>=8.0.0 \
    PyYAML>=5.4.0 \
    pyzmq>=22.0.0 \
    msgpack>=1.0.0 \
    zhon \
    nltk \
    distance \
    anyconfig \
    munch \
    tensorboardX \
    scipy \
    scikit-image \
    python-dotenv

# Set legacy Keras environment
ENV TF_USE_LEGACY_KERAS=1

# Source code should be mounted as volume at runtime:
# -v /path/to/starry-ocr:/app/starry-ocr:ro
ENV PYTHONPATH=/app/starry-ocr

# Default command
CMD ["python", "--help"]


# ============================================================
# Stage 4: All-in-one image (for convenience)
# ============================================================
FROM base AS all-in-one

WORKDIR /app

# Install all dependencies (larger image but simpler deployment)
# Using cu121 for compatibility with CUDA driver 12.4
# Note: numpy<2.0 required for imgaug compatibility
RUN pip install --no-cache-dir \
    "numpy>=1.26.0,<2.0.0" \
    torch==2.5.1 \
    torchvision==0.20.1 \
    --index-url https://download.pytorch.org/whl/cu121

RUN pip install --no-cache-dir \
    "numpy>=1.26.0,<2.0.0" \
    tensorflow==2.20.0 \
    tf_keras==2.20.1 \
    "opencv-python-headless<4.11" \
    Pillow>=8.0.0 \
    PyYAML>=5.4.0 \
    pyzmq>=22.0.0 \
    msgpack>=1.0.0 \
    dill \
    scipy \
    imgaug \
    scikit-image \
    zhon \
    nltk \
    distance \
    anyconfig \
    munch \
    tensorboardX \
    python-dotenv \
    pyclipper \
    shapely \
    polygon3 \
    Polygon3 \
    tqdm \
    fs \
    einops \
    lmdb

ENV TF_USE_LEGACY_KERAS=1

# Source code should be mounted as volumes at runtime:
# -v /path/to/deep-starry:/app/deep-starry:ro
# -v /path/to/starry-ocr:/app/starry-ocr:ro
ENV PYTHONPATH=/app/deep-starry:/app/starry-ocr

# Default working directory
WORKDIR /app

CMD ["python", "--help"]