Skip to content

Commit

Permalink
fix install in venv
Browse files Browse the repository at this point in the history
  • Loading branch information
daisycx committed Jun 29, 2022
1 parent 15aaea0 commit 811ee01
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 22 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ ImportError: /home//lib/python3.6/site-packages/mgeconvert/backend/ir_to_tflite/
| matrix mul |<br/>|<br/>|<br/>|
| max pool2d |<br/>|<br/>|<br/>|
| mul |<br/>|<br/>|<br/>|
| pad |<br/>× | ×<br/>× | ×<br/>× |
| pow |<br/>|<br/>|<br/>|
| reduce max |<br/>|<br/>|<br/>|
| reduce min |<br/>|<br/>|<br/>|
Expand Down Expand Up @@ -314,6 +315,7 @@ ImportError: /home//lib/python3.6/site-packages/mgeconvert/backend/ir_to_tflite/
| Concat |<br/>|
| Dropout |<br/>|
| Flatten |<br/>|
| Gather |<br/>|
| Gemm |<br/>|
| GlobalAveragePool |<br/>|
| GlobalMaxPool |<br/>|
Expand Down
2 changes: 1 addition & 1 deletion ci/pytest_caffe_and_onnx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ python3 -m pip install --no-binary=protobuf protobuf==3.11.1

apt install -y protobuf-compiler

./mgeconvert/backend/ir_to_caffe/init.sh
./mgeconvert/backend/ir_to_caffe/init.sh False /usr/bin/python3

pip3 install scikit-image==0.17.2 onnx onnxruntime

Expand Down
2 changes: 1 addition & 1 deletion ci/pytest_caffe_and_onnx_complete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ python3 -m pip install --no-binary=protobuf protobuf==3.11.1

apt install -y protobuf-compiler

./mgeconvert/backend/ir_to_caffe/init.sh
./mgeconvert/backend/ir_to_caffe/init.sh False /usr/bin/python3

pip3 install scikit-image==0.17.2 onnx onnxruntime

Expand Down
2 changes: 1 addition & 1 deletion ci/pytest_tflite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

./mgeconvert/backend/ir_to_tflite/build_flatbuffer.sh
./mgeconvert/backend/ir_to_tflite/init.sh
./mgeconvert/backend/ir_to_tflite/init.sh False /usr/bin/python3

sudo python3 -m pip uninstall flatbuffers -y
sudo python3 -m pip install tensorflow==2.5.0
Expand Down
2 changes: 1 addition & 1 deletion ci/pytest_tflite_complete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

./mgeconvert/backend/ir_to_tflite/build_flatbuffer.sh
./mgeconvert/backend/ir_to_tflite/init.sh
./mgeconvert/backend/ir_to_tflite/init.sh False /usr/bin/python3

# try to find libflatbuffers.so
export LD_LIBRARY_PATH=$HOME/.local/lib:$LD_LIBRARY_PATH:
Expand Down
9 changes: 8 additions & 1 deletion mgeconvert/backend/ir_to_caffe/init.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#!/bin/bash -e

python3 -m pip install --no-binary=protobuf "protobuf>=3.11.1" --user
ADD_USER=""
if [[ $1 == "False" ]]; then
ADD_USER="--user"
fi

PYTHON3=$2

$PYTHON3 -m pip install --no-binary=protobuf "protobuf>=3.11.1" $ADD_USER

hash wget || (echo "please install wget package" && exit -1)
hash protoc || (echo "please install protobuf-compiler package" && exit -1)
Expand Down
13 changes: 10 additions & 3 deletions mgeconvert/backend/ir_to_onnx/init.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/bin/bash -e

python3 -m pip install "onnx>=1.7.0" --user
python3 -m pip install onnx-simplifier --user
python3 -m pip install protobuf --user
ADD_USER=""
if [[ $1 == "False" ]]; then
ADD_USER="--user"
fi

PYTHON3=$2

$PYTHON3 -m pip install "onnx>=1.7.0,<1.12.0" $ADD_USER
$PYTHON3 -m pip install onnx-simplifier $ADD_USER
$PYTHON3 -m pip install protobuf $ADD_USER
26 changes: 16 additions & 10 deletions mgeconvert/backend/ir_to_tflite/init.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
#!/bin/bash -e
basepath=$(cd `dirname $0`; pwd)

ADD_USER=""
if [[ $1 == "False" ]]; then
ADD_USER="--user"
fi

PYTHON3=$2

if python3 -c "import flatbuffers">/dev/null 2>&1; then
FLAT_BUFFER_VERSION="$(python3 -m pip show flatbuffers | grep Version)"
if $PYTHON3 -c "import flatbuffers">/dev/null 2>&1; then
FLAT_BUFFER_VERSION="$($PYTHON3 -m pip show flatbuffers | grep Version)"
else
FLAT_BUFFER_VERSION=""
fi
echo ${FLAT_BUFFER_VERSION}

# install flatbuffers
if [[ "$FLAT_BUFFER_VERSION" != "Version: 1.12" ]]; then
python3 -m pip uninstall flatbuffers -y
$PYTHON3 -m pip uninstall flatbuffers -y
echo "install flatbuffers..."
python3 -m pip install flatbuffers==1.12 --user
$PYTHON3 -m pip install flatbuffers==1.12 $ADD_USER
fi

if [ ! -d /tmp/mgeconvert ]; then
Expand All @@ -26,8 +32,8 @@ export PATH=$PATH:$HOME/.local/bin
echo "building tflite schema..."
cd /tmp/mgeconvert
rm -f schema.fbs
tf_version=$1
if [ ! -n "$1" ] ;then
tf_version=$3
if [ ! -n "$3" ] ;then
tf_version="r2.3"
fi
echo "Use TFLite $tf_version!"
Expand All @@ -37,13 +43,13 @@ chmod 777 /tmp/mgeconvert/tflite
cp -r /tmp/mgeconvert/tflite $basepath


python3 -m pip install pybind11==2.6.2 --user
$PYTHON3 -m pip install pybind11==2.6.2 $ADD_USER

# using pyflexbuffers
cd $basepath/pyflexbuffers
PYBIND11_HEADER=$(python3 -c "import pybind11; print(pybind11.get_include())")
PYTHON_INCLUDE=$(python3 -c "import sysconfig; print(sysconfig.get_paths()['include'])")
PYTHON_STDLIB=$(python3 -c "import sysconfig; print(sysconfig.get_paths()['stdlib'])")
PYBIND11_HEADER=$($PYTHON3 -c "import pybind11; print(pybind11.get_include())")
PYTHON_INCLUDE=$($PYTHON3 -c "import sysconfig; print(sysconfig.get_paths()['include'])")
PYTHON_STDLIB=$($PYTHON3 -c "import sysconfig; print(sysconfig.get_paths()['stdlib'])")

g++ fbconverter.cc --std=c++14 -fPIC --shared -I$basepath/pyflexbuffers/include -I${PYBIND11_HEADER} -I${PYTHON_INCLUDE} -L${PYTHON_STDLIB} -L$basepath/pyflexbuffers/lib -lflatbuffers -o fbconverter.so

Expand Down
9 changes: 7 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

targets = []
tfversion = None
IS_VENV = hasattr(sys, "real_prefix") or (
hasattr(sys, "base_prefix") and sys.base_prefix != sys.prefix
)


def write_init(targets, tflite_schema_version=None):
Expand Down Expand Up @@ -97,9 +100,11 @@ def find_extension(self, name):
def build_all(self, ext):
if ext.script:
if ext.name == "tflite" and tfversion is not None:
subprocess.check_call([ext.script, tfversion])
subprocess.check_call(
[ext.script, str(IS_VENV), sys.executable, tfversion]
)
else:
subprocess.check_call(ext.script)
subprocess.check_call([ext.script, str(IS_VENV), sys.executable])
if ext.artifacts is not None:
self.copy_tree(ext.artifacts, os.path.join(self.build_lib, ext.artifacts))

Expand Down
2 changes: 1 addition & 1 deletion test/mge/test_tflite.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from mgeconvert.converters.mge_to_tflite import mge_to_tflite
from tensorflow.lite.python import interpreter # pylint: disable=import-error

max_error = 1e-6
max_error = 1e-4
tmp_file = "test_model"


Expand Down
5 changes: 5 additions & 0 deletions test/traced_module/test_qat_tflite.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@

from .tm_utils import get_traced_module

if mge.__version__ > "1.7.0":
from megengine.traced_module.tm_config import disable_default_checker

disable_default_checker()

max_error = 1e-4
tmp_file = "test_model"

Expand Down
2 changes: 1 addition & 1 deletion test/traced_module/test_tflite.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from mgeconvert.converters.tm_to_tflite import tracedmodule_to_tflite
from tensorflow.lite.python import interpreter # pylint: disable=import-error

max_error = 1e-6
max_error = 1e-4
tmp_file = "test_model"


Expand Down

0 comments on commit 811ee01

Please sign in to comment.