Commit ·
9688ab3
1
Parent(s): b936ff1
fix: Ajuste no caminho dos pesos dos modelos
Browse files- Dockerfile +0 -42
- app.py +2 -2
- dockerfile +8 -5
- src/models/inference.py +32 -8
Dockerfile
DELETED
|
@@ -1,42 +0,0 @@
|
|
| 1 |
-
FROM python:3.10-slim
|
| 2 |
-
|
| 3 |
-
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 4 |
-
PYTHONUNBUFFERED=1 \
|
| 5 |
-
PIP_NO_CACHE_DIR=1 \
|
| 6 |
-
PORT=7860 \
|
| 7 |
-
HOME=/home/user \
|
| 8 |
-
PATH=/home/user/.local/bin:$PATH \
|
| 9 |
-
HF_HOME=/tmp/.huggingface \
|
| 10 |
-
TRANSFORMERS_CACHE=/tmp/.cache/huggingface/transformers \
|
| 11 |
-
HUGGINGFACE_HUB_CACHE=/tmp/.cache/huggingface/hub
|
| 12 |
-
|
| 13 |
-
RUN useradd -m -u 1000 user
|
| 14 |
-
|
| 15 |
-
WORKDIR $HOME/app
|
| 16 |
-
|
| 17 |
-
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 18 |
-
build-essential \
|
| 19 |
-
gcc \
|
| 20 |
-
g++ \
|
| 21 |
-
git \
|
| 22 |
-
libglib2.0-0 \
|
| 23 |
-
libsm6 \
|
| 24 |
-
libxext6 \
|
| 25 |
-
libxrender1 \
|
| 26 |
-
libgomp1 \
|
| 27 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 28 |
-
|
| 29 |
-
RUN mkdir -p /tmp/.huggingface /tmp/.cache/huggingface/transformers /tmp/.cache/huggingface/hub
|
| 30 |
-
|
| 31 |
-
COPY --chown=user requirements.txt $HOME/app/requirements.txt
|
| 32 |
-
|
| 33 |
-
USER user
|
| 34 |
-
|
| 35 |
-
RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
|
| 36 |
-
pip install --no-cache-dir -r $HOME/app/requirements.txt
|
| 37 |
-
|
| 38 |
-
COPY --chown=user . $HOME/app
|
| 39 |
-
|
| 40 |
-
EXPOSE 7860
|
| 41 |
-
|
| 42 |
-
CMD ["python", "app.py"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import logging
|
|
| 4 |
|
| 5 |
logging.basicConfig(level=logging.INFO)
|
| 6 |
|
| 7 |
-
ROOT = os.path.dirname(__file__)
|
| 8 |
SRC = os.path.join(ROOT, "src")
|
| 9 |
|
| 10 |
if SRC not in sys.path:
|
|
@@ -20,4 +20,4 @@ if __name__ == "__main__":
|
|
| 20 |
server_name="0.0.0.0",
|
| 21 |
server_port=port,
|
| 22 |
share=False,
|
| 23 |
-
)
|
|
|
|
| 4 |
|
| 5 |
logging.basicConfig(level=logging.INFO)
|
| 6 |
|
| 7 |
+
ROOT = os.path.abspath(os.environ.get("APP_ROOT", os.path.dirname(__file__)))
|
| 8 |
SRC = os.path.join(ROOT, "src")
|
| 9 |
|
| 10 |
if SRC not in sys.path:
|
|
|
|
| 20 |
server_name="0.0.0.0",
|
| 21 |
server_port=port,
|
| 22 |
share=False,
|
| 23 |
+
)
|
dockerfile
CHANGED
|
@@ -5,6 +5,7 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
|
|
| 5 |
PIP_NO_CACHE_DIR=1 \
|
| 6 |
PORT=7860 \
|
| 7 |
HOME=/home/user \
|
|
|
|
| 8 |
PATH=/home/user/.local/bin:$PATH \
|
| 9 |
HF_HOME=/tmp/.huggingface \
|
| 10 |
TRANSFORMERS_CACHE=/tmp/.cache/huggingface/transformers \
|
|
@@ -12,7 +13,7 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
|
|
| 12 |
|
| 13 |
RUN useradd -m -u 1000 user
|
| 14 |
|
| 15 |
-
WORKDIR
|
| 16 |
|
| 17 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 18 |
build-essential \
|
|
@@ -28,15 +29,17 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
| 28 |
|
| 29 |
RUN mkdir -p /tmp/.huggingface /tmp/.cache/huggingface/transformers /tmp/.cache/huggingface/hub
|
| 30 |
|
| 31 |
-
COPY --chown=user requirements.txt $
|
| 32 |
|
| 33 |
USER user
|
| 34 |
|
| 35 |
RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
|
| 36 |
-
pip install --no-cache-dir -r $
|
| 37 |
|
| 38 |
-
COPY --chown=user . $
|
|
|
|
|
|
|
| 39 |
|
| 40 |
EXPOSE 7860
|
| 41 |
|
| 42 |
-
CMD ["python", "app.py"]
|
|
|
|
| 5 |
PIP_NO_CACHE_DIR=1 \
|
| 6 |
PORT=7860 \
|
| 7 |
HOME=/home/user \
|
| 8 |
+
APP_ROOT=/app \
|
| 9 |
PATH=/home/user/.local/bin:$PATH \
|
| 10 |
HF_HOME=/tmp/.huggingface \
|
| 11 |
TRANSFORMERS_CACHE=/tmp/.cache/huggingface/transformers \
|
|
|
|
| 13 |
|
| 14 |
RUN useradd -m -u 1000 user
|
| 15 |
|
| 16 |
+
WORKDIR /app
|
| 17 |
|
| 18 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 19 |
build-essential \
|
|
|
|
| 29 |
|
| 30 |
RUN mkdir -p /tmp/.huggingface /tmp/.cache/huggingface/transformers /tmp/.cache/huggingface/hub
|
| 31 |
|
| 32 |
+
COPY --chown=user requirements.txt $APP_ROOT/requirements.txt
|
| 33 |
|
| 34 |
USER user
|
| 35 |
|
| 36 |
RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
|
| 37 |
+
pip install --no-cache-dir -r $APP_ROOT/requirements.txt
|
| 38 |
|
| 39 |
+
COPY --chown=user . $APP_ROOT
|
| 40 |
+
|
| 41 |
+
VOLUME ["/app/data"]
|
| 42 |
|
| 43 |
EXPOSE 7860
|
| 44 |
|
| 45 |
+
CMD ["python", "app.py"]
|
src/models/inference.py
CHANGED
|
@@ -12,16 +12,39 @@ from models.cam import GradCAMPlusPlus
|
|
| 12 |
|
| 13 |
logging.basicConfig(level=logging.INFO)
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 16 |
-
PROJECT_ROOT =
|
|
|
|
| 17 |
|
| 18 |
CLASS_LIST = ["NEV", "BCC", "ACK", "SEK", "SCC", "MEL"]
|
| 19 |
|
| 20 |
-
ENCODER_DIR = os.path.join(
|
| 21 |
MODEL_ROOT_PATTERNS = [
|
| 22 |
os.path.join(
|
| 23 |
-
|
| 24 |
-
"data",
|
| 25 |
"weights",
|
| 26 |
"TO_BE_USED",
|
| 27 |
"*",
|
|
@@ -32,8 +55,7 @@ MODEL_ROOT_PATTERNS = [
|
|
| 32 |
"model_*_with_one-hot-encoder_512_with_best_architecture",
|
| 33 |
),
|
| 34 |
os.path.join(
|
| 35 |
-
|
| 36 |
-
"data",
|
| 37 |
"weights",
|
| 38 |
"TO_BE_USED",
|
| 39 |
"*",
|
|
@@ -68,10 +90,12 @@ _DISCOVERED = False
|
|
| 68 |
def _debug_paths() -> None:
|
| 69 |
print(f"[inference] DEVICE={DEVICE}")
|
| 70 |
print(f"[inference] PROJECT_ROOT={PROJECT_ROOT}")
|
|
|
|
|
|
|
| 71 |
print(f"[inference] ENCODER_DIR={ENCODER_DIR}")
|
| 72 |
print(f"[inference] ENCODER_DIR exists? {os.path.exists(ENCODER_DIR)}")
|
| 73 |
|
| 74 |
-
data_root =
|
| 75 |
weights_root = os.path.join(data_root, "weights")
|
| 76 |
to_be_used_root = os.path.join(weights_root, "TO_BE_USED")
|
| 77 |
|
|
@@ -238,7 +262,7 @@ def _get_model_and_cam(model_key):
|
|
| 238 |
if not MODEL_CONFIGS:
|
| 239 |
raise RuntimeError(
|
| 240 |
f"No compatible model checkpoints were found in "
|
| 241 |
-
f"{os.path.join(
|
| 242 |
f"Please verify that the model assets were uploaded to the Space."
|
| 243 |
)
|
| 244 |
|
|
|
|
| 12 |
|
| 13 |
logging.basicConfig(level=logging.INFO)
|
| 14 |
|
| 15 |
+
|
| 16 |
+
def _resolve_project_root() -> str:
|
| 17 |
+
app_root = os.path.abspath(
|
| 18 |
+
os.environ.get(
|
| 19 |
+
"APP_ROOT",
|
| 20 |
+
os.path.join(os.path.dirname(__file__), "..", ".."),
|
| 21 |
+
)
|
| 22 |
+
)
|
| 23 |
+
return app_root
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def _resolve_data_root(project_root: str) -> str:
|
| 27 |
+
explicit_data_root = os.environ.get("DATA_ROOT")
|
| 28 |
+
if explicit_data_root:
|
| 29 |
+
return os.path.abspath(explicit_data_root)
|
| 30 |
+
|
| 31 |
+
hf_persistent_root = "/data"
|
| 32 |
+
if os.path.exists(hf_persistent_root):
|
| 33 |
+
return hf_persistent_root
|
| 34 |
+
|
| 35 |
+
return os.path.join(project_root, "data")
|
| 36 |
+
|
| 37 |
+
|
| 38 |
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 39 |
+
PROJECT_ROOT = _resolve_project_root()
|
| 40 |
+
DATA_ROOT = _resolve_data_root(PROJECT_ROOT)
|
| 41 |
|
| 42 |
CLASS_LIST = ["NEV", "BCC", "ACK", "SEK", "SCC", "MEL"]
|
| 43 |
|
| 44 |
+
ENCODER_DIR = os.path.join(DATA_ROOT, "preprocess_data")
|
| 45 |
MODEL_ROOT_PATTERNS = [
|
| 46 |
os.path.join(
|
| 47 |
+
DATA_ROOT,
|
|
|
|
| 48 |
"weights",
|
| 49 |
"TO_BE_USED",
|
| 50 |
"*",
|
|
|
|
| 55 |
"model_*_with_one-hot-encoder_512_with_best_architecture",
|
| 56 |
),
|
| 57 |
os.path.join(
|
| 58 |
+
DATA_ROOT,
|
|
|
|
| 59 |
"weights",
|
| 60 |
"TO_BE_USED",
|
| 61 |
"*",
|
|
|
|
| 90 |
def _debug_paths() -> None:
|
| 91 |
print(f"[inference] DEVICE={DEVICE}")
|
| 92 |
print(f"[inference] PROJECT_ROOT={PROJECT_ROOT}")
|
| 93 |
+
print(f"[inference] DATA_ROOT={DATA_ROOT}")
|
| 94 |
+
print(f"[inference] DATA_ROOT exists? {os.path.exists(DATA_ROOT)}")
|
| 95 |
print(f"[inference] ENCODER_DIR={ENCODER_DIR}")
|
| 96 |
print(f"[inference] ENCODER_DIR exists? {os.path.exists(ENCODER_DIR)}")
|
| 97 |
|
| 98 |
+
data_root = DATA_ROOT
|
| 99 |
weights_root = os.path.join(data_root, "weights")
|
| 100 |
to_be_used_root = os.path.join(weights_root, "TO_BE_USED")
|
| 101 |
|
|
|
|
| 262 |
if not MODEL_CONFIGS:
|
| 263 |
raise RuntimeError(
|
| 264 |
f"No compatible model checkpoints were found in "
|
| 265 |
+
f"{os.path.join(DATA_ROOT, 'weights')}. "
|
| 266 |
f"Please verify that the model assets were uploaded to the Space."
|
| 267 |
)
|
| 268 |
|