Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.git
__pycache__/
*.pyc

data/*
!data/ForAINetV2/
!data/ForAINetV2/**

downloads/
work_dirs/*
!work_dirs/forestmamba_chm_radius16_qp300_2many_v6/
!work_dirs/forestmamba_chm_radius16_qp300_2many_v6/v6_epoch_1500_fix.pth

**/.pytest_cache/
**/.mypy_cache/
137 changes: 137 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: Build and Push Docker Image on Release

on:
release:
types: [published]
workflow_dispatch:

env:
REGISTRY: ghcr.io
IMAGE_NAME: 3dtrees-earth/3dtrees_forestmamba
BASE_IMAGE: ghcr.io/kgerb/forestmamba-image:3dtrees-base
CHECKPOINT_FILE_ID: 1XJ__eeYUDLbdaj77f_ryxydIs3FiTQaT
CHECKPOINT_PATH: work_dirs/forestmamba_chm_radius16_qp300_2many_v6/v6_epoch_1500_fix.pth
CHECKPOINT_SHA256: a398d6e5e79af8ce9cf697fdd10b1887927dc838cdafcb5ae5c3352a2d56d96a

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable={{is_default_branch}}

- name: Free space
run: |
sudo rm -rf \
/opt/hostedtoolcache \
/opt/google/chrome \
/opt/microsoft/msedge \
/opt/microsoft/powershell \
/opt/pipx \
/usr/local/julia* \
/usr/local/lib/android \
/usr/local/lib/node_modules \
/usr/local/share/chromium \
/usr/local/share/powershell \
/usr/share/dotnet \
/usr/share/swift

- name: Download ForestMamba checkpoint
run: |
python -m pip install --user --no-cache-dir gdown
mkdir -p "$(dirname "${CHECKPOINT_PATH}")"
python -m gdown --id "${CHECKPOINT_FILE_ID}" -O "${CHECKPOINT_PATH}"
echo "${CHECKPOINT_SHA256} ${CHECKPOINT_PATH}" | sha256sum -c -

- name: Build and push Docker image
env:
DOCKER_METADATA_OUTPUT_LABELS: ${{ steps.meta.outputs.labels }}
DOCKER_METADATA_OUTPUT_TAGS: ${{ steps.meta.outputs.tags }}
run: |
mapfile -t tags <<< "${DOCKER_METADATA_OUTPUT_TAGS}"
mapfile -t labels <<< "${DOCKER_METADATA_OUTPUT_LABELS}"

tag_args=()
for tag in "${tags[@]}"; do
[ -n "${tag}" ] || continue
tag_args+=(--tag "${tag}")
done
if [ "${#tag_args[@]}" -eq 0 ]; then
echo "No Docker tags were generated by docker/metadata-action." >&2
exit 1
fi

label_args=()
for label in "${labels[@]}"; do
[ -n "${label}" ] || continue
label_args+=(--label "${label}")
done

docker build \
--file Dockerfile.3dtrees \
--build-arg "BASE_IMAGE=${BASE_IMAGE}" \
"${tag_args[@]}" \
"${label_args[@]}" \
.

for tag in "${tags[@]}"; do
[ -n "${tag}" ] || continue
docker push "${tag}"
done

- name: Add image details to release
if: github.event_name == 'release'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
DOCKER_METADATA_OUTPUT_TAGS: ${{ steps.meta.outputs.tags }}
run: |
{
echo "### Container images"
echo
echo "Published image tags:"
while IFS= read -r tag; do
[ -n "${tag}" ] || continue
echo "- \`${tag}\`"
done <<< "${DOCKER_METADATA_OUTPUT_TAGS}"
echo
echo "Base image:"
echo "- \`${BASE_IMAGE}\`"
} > release-image-notes.md

gh release view "${RELEASE_TAG}" --json body --jq .body > release-body.md
if grep -F "### Container images" release-body.md >/dev/null; then
echo "Release already contains container image details."
exit 0
fi

{
cat release-body.md
echo
cat release-image-notes.md
} > updated-release-body.md
gh release edit "${RELEASE_TAG}" --notes-file updated-release-body.md
35 changes: 35 additions & 0 deletions Dockerfile.3dtrees
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
ARG BASE_IMAGE=ghcr.io/kgerb/forestmamba-image:3dtrees-base
FROM ${BASE_IMAGE}

ARG TORCH_CUDA_ARCH_LIST="6.1;7.0;8.0;8.6"

RUN pip install --no-cache-dir \
mamba-ssm==1.1.1 \
causal-conv1d==1.1.1 \
hilbertcurve==2.0.5 \
transformers==4.36.0 \
importlib-metadata==4.13.0 \
wandb==0.16.6 \
"laspy[lazrs]==2.5.4"

RUN pip uninstall -y torch-cluster torch-points-kernels \
&& TORCH_CUDA_ARCH_LIST="${TORCH_CUDA_ARCH_LIST}" FORCE_CUDA=1 pip install --no-deps --no-cache-dir torch-cluster==1.6.3 \
&& TORCH_CUDA_ARCH_LIST="${TORCH_CUDA_ARCH_LIST}" FORCE_CUDA=1 pip install --no-deps --no-cache-dir torch-points-kernels==0.7.0

ARG CHECKPOINT_PATH=/workspace/work_dirs/forestmamba_chm_radius16_qp300_2many_v6/v6_epoch_1500_fix.pth
COPY . /workspace
RUN test -s "${CHECKPOINT_PATH}"
RUN chmod -R a+rX /workspace

COPY replace_mmdetection_files/loops.py /opt/conda/lib/python3.10/site-packages/mmengine/runner/loops.py
COPY replace_mmdetection_files/base_model.py /opt/conda/lib/python3.10/site-packages/mmengine/model/base_model/base_model.py
COPY replace_mmdetection_files/transforms_3d.py /opt/conda/lib/python3.10/site-packages/mmdet3d/datasets/transforms/transforms_3d.py
COPY replace_mmdetection_files/distributed.py /opt/conda/lib/python3.10/site-packages/mmengine/model/wrappers/distributed.py
RUN chmod a+r \
/opt/conda/lib/python3.10/site-packages/mmengine/runner/loops.py \
/opt/conda/lib/python3.10/site-packages/mmengine/model/base_model/base_model.py \
/opt/conda/lib/python3.10/site-packages/mmdet3d/datasets/transforms/transforms_3d.py \
/opt/conda/lib/python3.10/site-packages/mmengine/model/wrappers/distributed.py

ENV PYTHONPATH=/workspace
ENV WANDB_MODE=disabled
Loading