From d98aac3c3a48ec63945da43b2a9efd84d08a0e42 Mon Sep 17 00:00:00 2001 From: Youshaa Murhij Date: Sun, 11 Feb 2024 15:49:31 +0300 Subject: [PATCH] update readme and add docker files --- .gitignore | 1 - LICENSE | 2 +- README.md | 78 ++++++++++++++++++++++++++++++++++++++++ configs/custom.yaml | 2 +- docker/Dockerfile.x86_64 | 63 ++++++++++++++++++++++++++++++++ docker/build.sh | 22 ++++++++++++ docker/into.sh | 7 ++++ docker/start.sh | 52 +++++++++++++++++++++++++++ 8 files changed, 224 insertions(+), 3 deletions(-) create mode 100644 docker/Dockerfile.x86_64 create mode 100644 docker/build.sh create mode 100644 docker/into.sh create mode 100644 docker/start.sh diff --git a/.gitignore b/.gitignore index 4a8adff3..aee53417 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,4 @@ /vis/vis_results /outputs* **.pth -/docker /evaluation/**.txt \ No newline at end of file diff --git a/LICENSE b/LICENSE index 024a5a8c..679d1db8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 HYOJUN LEE +Copyright (c) 2023 YOUSHAA MURHIJ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 642f4bb7..71d971ff 100644 --- a/README.md +++ b/README.md @@ -23,3 +23,81 @@ ${CODE Root} - Download annotation files to fill in `apollo_annot` [[hear](https://drive.google.com/file/d/1qCUdjJEnKS7jyXDVuDBO5wCYZFeo1VsY/view?usp=sharing)]. - Download image files to fill in `images` [[hear](https://apolloscape.auto/car_instance.html)]. + + +## Usage: +For Docker container usage, run: +```bash +git clone DAGM-Mono +cd DAGM-Mono + +bash docker/build.sh + +bash docker/start.sh +bash docker/into.sh +``` +From Conda environment usage, run: +```bash +conda create -n dagm_mono python=3.9 +conda activate dagm_mono + +#pytorch +conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 cudatoolkit=11.3 -c pytorch -c conda-forge + +# detectron2 +python -m pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu113/torch1.10/index.html + + +conda install -c fvcore -c iopath -c conda-forge fvcore iopath + +conda install -c bottler nvidiacub + +conda install pytorch3d -c pytorch3d + +pip install -r requirements.txt +pip install open3d==0.14.1 + +``` + +## Train +1. To stable model convergence, we follow BAAM method to first train the 2D modules (Box, Keypoint). You can downlod pre-trained 2D module weights from [here](https://drive.google.com/file/d/1aX_-SfHtXAdE-frgrbrlQYuWddhwX3V3/view?usp=drive_link). +2. Replace it the third line of `configs/custom.yaml`. +3. Run the command below. +```bash + python main.py -t +``` + +## Inference +To run inference, update the weights path in the yaml config file and run: +```bash + python main.py +``` + + +## Evaluation +1. Finish either inference process or train process. +2. Move to `evaluation` folder. +3. Run the command below. +```bash + python eval.py \ + --light \ + --test_dir ../outputs/res \ + --gt_dir ../data/apollo/val/apollo_annot \ + --res_file test_results.txt +``` +4. You can show A3DP results in `test_results.txt`. + +## Visualization +1. Install open3D python library +2. Move to 'vis' folder. +3. Run the command below. +```bash + python vis_apollo.py \ + --output [path where the results are saved] \ + --file [file name to vis] \ + --save [path to save vis results] + +``` + +## License +DAGM-Mono is released under MIT license (see LICENSE). It is developed based on a forked version of BAAM. We also used code from OFMPNet, Swin-Transformer and FMFNet. Note that the used dataset (ApolloCar3D) is subject to their respective licenses and may not grant commercial use. diff --git a/configs/custom.yaml b/configs/custom.yaml index 6566b8e8..8e6e37b3 100644 --- a/configs/custom.yaml +++ b/configs/custom.yaml @@ -1,6 +1,6 @@ _BASE_: "res2net-bifpn.yaml" MODEL: - WEIGHTS: best_rel_model.pth #res2net_bifpn.pth + WEIGHTS: pretrained/res2net_bifpn.pth DEVICE: 'cuda:0' BACKBONE: FREEZE_AT: 2 diff --git a/docker/Dockerfile.x86_64 b/docker/Dockerfile.x86_64 new file mode 100644 index 00000000..8c5c6697 --- /dev/null +++ b/docker/Dockerfile.x86_64 @@ -0,0 +1,63 @@ +FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04 + +ENV DEBIAN_FRONTEND=noninteractive + +#Install required apt libs and packages +RUN apt-get update -y && \ + apt-get autoremove -y && \ + apt-get install -y --no-install-recommends \ + wget \ + curl \ + python3.9 \ + python3-pip \ + python3-dev\ + python3-tk \ + ca-certificates \ + lsb-release \ + ninja-build \ + build-essential \ + git \ + software-properties-common \ + cmake \ + libx11-6 ffmpeg libsm6 libxext6 \ + libegl1 \ + libgl1 \ + libgomp1 \ + && rm -rf /var/lib/apt/lists/* \ + && apt-get clean + +# Update pip & install pytorch +RUN python3 -m pip install pip --upgrade + +RUN pip install torch==2.0.0+cu118 torchvision==0.15.1+cu118 --index-url https://download.pytorch.org/whl/cu118 + +# Set up environment Arch +ENV TORCH_CUDA_ARCH_LIST="5.2 6.0 6.1 7.0 7.5 8.0 8.6+PTX" + + +RUN FORCE_CUDA=1 python3 -m pip install 'git+https://github.com/facebookresearch/detectron2.git@v0.6' +RUN python3 -m pip install "git+https://github.com/facebookresearch/pytorch3d.git" + +RUN python3 -m pip install \ + setuptools \ + tim \ + opencv-python + +# Install Open3D from the PyPI repositories +# RUN python3 -m pip install --no-cache-dir --upgrade pip && \ +# python3.9 -m pip install --no-cache-dir --upgrade open3d==0.14.1 + +# User setup +ARG USER=user +ARG UID=1000 +ARG GID=1000 +# default password +ARG PW=user + +RUN useradd -m ${USER} --uid=${UID} && echo "${USER}:${PW}" | chpasswd && adduser ${USER} sudo + +WORKDIR /home/${USER} +RUN cd /home/${USER} && mkdir -p dagm_mono && chown -R ${UID}:${GID} ./ + +USER ${UID}:${GID} + diff --git a/docker/build.sh b/docker/build.sh new file mode 100644 index 00000000..282174d1 --- /dev/null +++ b/docker/build.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +yellow=`tput setaf 3` +green=`tput setaf 2` +violet=`tput setaf 5` +reset_color=`tput sgr0` + +ARCH="$(uname -m)" + +main () { + pushd "$(dirname "$0")"; + if [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "aarch64" ]; then + file="./Dockerfile.${ARCH}" + else + echo "There is no Dockerfile for ${yellow}${ARCH}${reset_color} arch" + fi + echo "Building image for ${yellow}${ARCH}${reset_color} arch. from Dockerfile: ${yellow}${file}${reset_color}" + docker build -f ${file} . -t ${ARCH}/dagm_mono:latest; + popd; +} + +main "$@"; exit; diff --git a/docker/into.sh b/docker/into.sh new file mode 100644 index 00000000..50f8fcb3 --- /dev/null +++ b/docker/into.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +docker exec -it --user "user" dagm_mono \ + /bin/bash -c " + cd /home/user/dagm_mono; + export PYTHONPATH=\"${PYTHONPATH}:/home/user/dagm_mono\"; + /bin/bash" diff --git a/docker/start.sh b/docker/start.sh new file mode 100644 index 00000000..186300ec --- /dev/null +++ b/docker/start.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +cd "$(dirname "$0")" +cd .. + +workspace_dir=$PWD +desktop_start() { + docker run --ipc=host -it -d --rm \ + --gpus 'all,"capabilities=compute,utility,graphics"' \ + --env="DISPLAY" \ + --env="QT_X11_NO_MITSHM=1" \ + --privileged \ + --name dagm_mono \ + --net "host" \ + -v /tmp/.X11-unix:/tmp/.X11-unix:rw \ + -v $workspace_dir/:/home/user/dagm_mono:rw \ + ${ARCH}/dagm_mono:latest + + XAUTH=/tmp/.docker.xauth + + xauth_list=$(xauth nlist :0 | tail -n 1 | sed -e 's/^..../ffff/') + if [ ! -f $XAUTH ]; then + if [ ! -z "$xauth_list" ]; then + echo $xauth_list | xauth -f $XAUTH nmerge - + else + touch $XAUTH + fi + chmod a+r $XAUTH + fi + + file $XAUTH + ls -FAlh $XAUTH +} + + +main () { + if [ "$(docker ps -aq -f status=exited -f name=dagm_mono)" ]; then + docker rm dagm_mono; + fi + + ARCH="$(uname -m)" + + desktop_start; + + docker exec -it --user "user" dagm_mono \ + /bin/bash -c " + cd /home/user/dagm_mono; + "; +} + +main; +