Last active
March 19, 2021 03:25
-
-
Save KuanYuChang/bc174e4f25c2eabce19245a1b053b2f0 to your computer and use it in GitHub Desktop.
Tested on Giselle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Cause the script to exit on any errors | |
# Reference: https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ | |
set -eo pipefail | |
# use CUDA 9.0 | |
chcuda 9.0 | |
# common variables | |
export W_SPACE=${HOME}/WorkSpace | |
export VIR_ENV=${W_SPACE}/py37 | |
export PYTORCH=${W_SPACE}/pytorch | |
export TORCH_INCLUDE_PATH=${VIR_ENV}/lib/python3.7/site-packages/torch/include | |
export COCOAPI=${W_SPACE}/cocoapi | |
export DENSEPOSE=${W_SPACE}/densepose | |
# create a workspace | |
mkdir -p ${W_SPACE} | |
cd ${W_SPACE} | |
# initialize a virtual environment with Python 3.7 | |
virtualenv -p python3.7 ${VIR_ENV} | |
source ${VIR_ENV}/bin/activate | |
# install dependencies | |
pip install pyyaml | |
pip install protobuf==3.6.1 | |
pip install future | |
pip install numpy | |
pip install cython | |
# install pytorch | |
git clone https://github.com/pytorch/pytorch.git ${PYTORCH} | |
cd ${PYTORCH} | |
git checkout v1.1.0 | |
git submodule update --init --recursive | |
python setup.py install | |
echo "export PYTHONPATH=${PYTORCH}/caffe2" | tee -a ${VIR_ENV}/bin/activate | |
sed -i '/^deactivate ().*/a \ \ \ \ unset PYTHONPATH' ${VIR_ENV}/bin/activate | |
# install the COCO API | |
git clone https://github.com/cocodataset/cocoapi.git ${COCOAPI} | |
cd ${COCOAPI}/PythonAPI | |
make install | |
# clone the Densepose repository | |
git clone https://github.com/Johnqczhang/DensePose ${DENSEPOSE} | |
cd ${DENSEPOSE} | |
# prepare CMakeList for building Densepose | |
curl -LO https://github.com/Johnqczhang/densepose_installation/raw/master/CMakeLists.txt | |
sed -i -e "s|/path/to/anaconda3/envs/py37/lib/python3.7/site-packages/torch/share/cmake/Caffe2|${VIR_ENV}/lib/python3.7/site-packages/torch/share/cmake/Caffe2|" CMakeLists.txt | |
sed -i -e "s|/path/to/your/cudnn/include|${CUDA_HOME}/include|" CMakeLists.txt | |
sed -i -e "s|/path/to/your/libcudnn/libcudnn.so|${CUDA_HOME}/lib64/libcudnn.so|" CMakeLists.txt | |
sed -i -e "s|/path/to/anaconda3/envs/py37/include|${VIR_ENV}/include/python3.7m ${TORCH_INCLUDE_PATH}|" CMakeLists.txt | |
sed -i -e "s|/path/to/anaconda3/envs/py37/lib/libprotobuf.a|/usr/local/lib/libprotobuf.a|" CMakeLists.txt | |
# copy source files of Caffe2 from pytorch repo | |
cp -r $PYTORCH/caffe2/utils/threadpool ${TORCH_INCLUDE_PATH}/caffe2/utils/ | |
cp -r $PYTORCH/caffe2/utils/math ${TORCH_INCLUDE_PATH}/caffe2/utils/ | |
# start building Densepose | |
mkdir -p ${DENSEPOSE}/build | |
cd ${DENSEPOSE}/build | |
cmake .. | |
make -j8 | |
# install Densepose | |
cd ${DENSEPOSE} | |
python setup.py develop | |
# logout then login to refresh env variables | |
# $ export W_SPACE=${HOME}/WorkSpace | |
# $ export VIR_ENV=${W_SPACE}/py37 | |
# $ export DENSEPOSE=${W_SPACE}/densepose | |
# $ source ${VIR_ENV}/bin/activate | |
# check Caffe2 GPU build was successful: must print a number > 0 | |
# $ python -c 'from caffe2.python import workspace; print(workspace.NumCudaDevices())' | |
# test Densepose | |
# $ python ${DENSEPOSE}/detectron/tests/test_zero_even_op.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment