# EffiRLD (EDANet-RBMTL) inference image.
#
#   CPU (default) : docker build -t effirld:cpu .
#   NVIDIA GPU    : docker build --build-arg TORCH_INDEX=cu128 -t effirld:gpu .
#
#   docker run --rm effirld:cpu                                   # runs selftest.py
#   docker run --rm -v "$PWD/images:/data" -v "$PWD/out:/out" effirld:cpu \
#       python predict.py --input /data --output /out --overlay
#   docker run --rm --gpus all ... effirld:gpu python predict.py ... --device cuda
FROM python:3.12-slim

ARG TORCH_VERSION=2.11.0
ARG TORCH_INDEX=cpu

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1

WORKDIR /opt/OpenPack

# Dependencies first, so code changes do not invalidate this layer.
COPY env/requirements-pinned.txt env/requirements-pinned.txt
RUN pip install "torch==${TORCH_VERSION}" --index-url "https://download.pytorch.org/whl/${TORCH_INDEX}" \
 && pip install -r env/requirements-pinned.txt

COPY edanet_rbmtl/ edanet_rbmtl/
COPY checkpoints/ checkpoints/
COPY configs/ configs/
COPY samples/ samples/
COPY reference_source/ reference_source/
COPY predict.py selftest.py evaluate_h5.py crosscheck_repo.py \
     class.txt palette.txt requirements.txt \
     README.md README.zh-TW.md LICENSE NOTICE CITATION.cff ./

LABEL org.opencontainers.image.title="EffiRLD" \
      org.opencontainers.image.description="High-Efficiency UAV Rice Lodging Recognition Model (EDANet-RBMTL) - inference" \
      org.opencontainers.image.version="lodg01" \
      org.opencontainers.image.licenses="Apache-2.0"

CMD ["python", "selftest.py"]
