3 # Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
19 DRIVER_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
21 VENV_ACTIVATE=${DRIVER_PATH}/venv/bin/activate
22 # NOTE please use venv's python instead of python after `source activation`.
23 # This script is called by debian maintainer script, i.e. `postinst`.
24 # Since debian maintainer script is called with sudo, `source activation` is ignored.
25 VENV_PYTHON=${DRIVER_PATH}/venv/bin/python
27 if [ ! -f ${VENV_ACTIVATE} ]; then
28 # Create python virtual enviornment
29 python3 -m venv "${DRIVER_PATH}/venv"
33 # - https://github.com/onnx/onnx/blob/master/docs/Versioning.md
34 # - https://github.com/onnx/onnx-tensorflow/blob/master/Versioning.md
38 VER_ONNXRUNTIME=1.15.0
44 PIP_TRUSTED_HOST="--trusted-host pypi.org "
45 PIP_TRUSTED_HOST+="--trusted-host pypi.python.org "
46 PIP_TRUSTED_HOST+="--trusted-host files.pythonhosted.org "
47 PIP_TRUSTED_HOST+="--trusted-host download.pytorch.org "
49 PIP_TIMEOUT="--default-timeout=1000 "
51 PIP_OPTIONS="${PIP_TIMEOUT} ${PIP_TRUSTED_HOST}"
53 # NOTE $ONE_PREPVENV_PIP_OPTION is to provide additional PIP options
54 # such as ceritificate file behind firewall
55 # ex) ONE_PREPVENV_PIP_OPTION="--cert SomePrivateCetificate.crt" ./one-prepare-venv
56 if [[ ! -z "$ONE_PREPVENV_PIP_OPTION" ]]; then
57 PIP_OPTIONS+=" ${ONE_PREPVENV_PIP_OPTION} "
60 ${VENV_PYTHON} -m pip ${PIP_OPTIONS} install --upgrade pip setuptools
61 if [ -n "${EXT_TENSORFLOW_WHL}" ]; then
62 ${VENV_PYTHON} -m pip ${PIP_OPTIONS} install ${EXT_TENSORFLOW_WHL}
64 ${VENV_PYTHON} -m pip ${PIP_OPTIONS} install tensorflow==${VER_TENSORFLOW}
66 ${VENV_PYTHON} -m pip ${PIP_OPTIONS} install Pillow
67 # Fix version to that of TF release date
68 ${VENV_PYTHON} -m pip ${PIP_OPTIONS} install tensorflow_probability==0.20.1
69 #${VENV_PYTHON} -m pip ${PIP_OPTIONS} install tensorflow_addons==0.20.0
73 # - Since tensorflow_addons 0.20.0 package distribution does not exist, it is
74 # configured to build using the source code at the time of
75 # one-prepare-env. This is not a perfect solution as it requires a build
76 # environment at install time.
78 # - Later, it is necessary to change the pre-built package to be uploaded
79 # and downloaded at the time of installation. (Or expect the appropriate
80 # tensorflow_addons official package to be distributed.)
82 # Make tempolary workspace for build
83 BAZEL_BUILD_PATH=$(mktemp -d)
84 pushd $BAZEL_BUILD_PATH
87 # Download tensorflow_addons source
88 git clone https://github.com/tensorflow/addons.git
90 git checkout -b r0.20 origin/r0.20
93 wget https://github.com/bazelbuild/bazelisk/releases/download/v1.17.0/bazelisk-linux-arm64
94 chmod 755 bazelisk-linux-arm64
95 ln -s bazelisk-linux-arm64 bazel
97 # This script links project with TensorFlow dependency
98 python3 ./configure.py
101 ./bazel build build_pip_pkg
102 bazel-bin/build_pip_pkg artifacts
104 # Install tensroflow_addons
105 ${VENV_PYTHON} -m pip ${PIP_OPTIONS} install artifacts/tensorflow_addons-*.whl
107 # Remove tempolary workspace
110 rm -rf $BAZEL_BUILD_PATH
112 # Install PyTorch and ONNX related
113 # NOTE set ONE_PREPVENV_TORCH_STABLE to override 'torch_stable.html' URL.
114 # torch_stable.html points to download URL of torch wheel file(s)
115 # but sometimes the server gets unstable, especially from in-house CI.
116 TORCH_STABLE_URL="https://download.pytorch.org/whl/torch_stable.html"
117 if [[ ! -z "$ONE_PREPVENV_TORCH_STABLE" ]]; then
118 TORCH_STABLE_URL="${ONE_PREPVENV_TORCH_STABLE}"
120 # TODO remove torch message
121 echo "Torch from '${ONE_PREPVENV_TORCH_STABLE}' -> '${TORCH_STABLE_URL}'"
122 ${VENV_PYTHON} -m pip ${PIP_OPTIONS} install torch==1.13.1 -f ${TORCH_STABLE_URL}
124 ${VENV_PYTHON} -m pip ${PIP_OPTIONS} install onnx==${VER_ONNX}
126 ${VENV_PYTHON} -m pip ${PIP_OPTIONS} install onnxruntime==${VER_ONNXRUNTIME}
128 # Provide install of custom onnx-tf
129 if [ -n "${EXT_ONNX_TF_WHL}" ]; then
130 ${VENV_PYTHON} -m pip ${PIP_OPTIONS} install ${EXT_ONNX_TF_WHL}
132 ${VENV_PYTHON} -m pip ${PIP_OPTIONS} install onnx-tf==${VER_ONNX_TF}
135 # Fix version to that of TF release date
136 ${VENV_PYTHON} -m pip ${PIP_OPTIONS} install --upgrade protobuf==4.23.3
138 # Install pydot for visq
139 ${VENV_PYTHON} -m pip ${PIP_OPTIONS} install pydot==${VER_PYDOT}