forked from openvinotoolkit/training_extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_venv.sh
executable file
·99 lines (74 loc) · 3.06 KB
/
init_venv.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env bash
set -v
set -x
work_dir=$(realpath "$(dirname $0)")
venv_dir=$1
if [ -z "$venv_dir" ]; then
venv_dir=venv
fi
cd ${work_dir}
if [[ -e ${venv_dir} ]]; then
echo
echo "Virtualenv already exists. Use command to start working:"
echo "$ . ${venv_dir}/bin/activate"
exit
fi
CUDA_HOME_CANDIDATE=/usr/local/cuda
if [ -z "${CUDA_HOME}" ] && [ -d ${CUDA_HOME_CANDIDATE} ]; then
echo "Exporting CUDA_HOME as ${CUDA_HOME_CANDIDATE}"
export CUDA_HOME=${CUDA_HOME_CANDIDATE}
fi
# Download mmdetection
git submodule update --init ../../external/mmdetection
# Create virtual environment
virtualenv ${venv_dir} -p python3 --prompt="(text_spotting)"
path_openvino_vars="${INTEL_OPENVINO_DIR:-/opt/intel/openvino_2021}/bin/setupvars.sh"
if [[ -e "${path_openvino_vars}" ]]; then
echo ". ${path_openvino_vars}" >> ${venv_dir}/bin/activate
fi
. ${venv_dir}/bin/activate
# upgrade pip to the latest version
pip install -U pip
if [ -z ${CUDA_VERSION} ] && [ -e "$CUDA_HOME/version.txt" ]; then
# Get CUDA version from version.txt file.
CUDA_VERSION=$(cat $CUDA_HOME/version.txt | sed -e "s/^.*CUDA Version *//" -e "s/ .*//")
fi
if [[ -z ${CUDA_VERSION} ]]; then
# Get CUDA version from nvidia-smi output.
CUDA_VERSION=$(nvidia-smi | grep "CUDA Version" | sed -e "s/^.*CUDA Version: *//" -e "s/ .*//")
fi
echo "Using CUDA_VERSION as ${CUDA_VERSION}"
# Remove dots from CUDA version string, if any.
CUDA_VERSION_CODE=$(echo ${CUDA_VERSION} | sed -e "s/\.//" -e "s/\(...\).*/\1/")
# install ote.
pip install -e ../../ote/ -c constraints.txt
# install PyTorch and MMCV.
export TORCH_VERSION=1.8.1
export TORCHVISION_VERSION=0.9.1
export MMCV_VERSION=1.3.0
if [[ $CUDA_VERSION_CODE == "102" ]]; then
pip install torch==${TORCH_VERSION} torchvision==${TORCHVISION_VERSION} -c constraints.txt
else
pip install torch==${TORCH_VERSION}+cu${CUDA_VERSION_CODE} torchvision==${TORCHVISION_VERSION}+cu${CUDA_VERSION_CODE} -f https://download.pytorch.org/whl/torch_stable.html -c constraints.txt
fi
pip uninstall -y mmcv
pip install --no-cache-dir mmcv-full==${MMCV_VERSION} -f https://download.openmmlab.com/mmcv/dist/cu${CUDA_VERSION_CODE}/torch${TORCH_VERSION}/index.html -c constraints.txt
# Install other requirements.
cat requirements.txt | xargs -n 1 -L 1 pip3 install -c constraints.txt
mo_requirements_file="${INTEL_OPENVINO_DIR:-/opt/intel/openvino_2021}/deployment_tools/model_optimizer/requirements_onnx.txt"
if [[ -e "${mo_requirements_file}" ]]; then
pip install -r ${mo_requirements_file} -c constraints.txt
else
echo "[WARNING] Model optimizer requirements were not installed. Please install the OpenVino toolkit to use one."
fi
pip install -e ../../external/mmdetection/ -c constraints.txt
MMDETECTION_DIR=`realpath ../../external/mmdetection/`
echo "export MMDETECTION_DIR=${MMDETECTION_DIR}" >> ${venv_dir}/bin/activate
echo "export CUDA_HOME=${CUDA_HOME}" >> ${venv_dir}/bin/activate
# check PyPI conflicts and print installed python packages
pip check
pip freeze
deactivate
echo
echo "Activate a virtual environment to start working:"
echo "$ . ${venv_dir}/bin/activate"