TensorFlow集成KTFOP使能鲲鹏算子加速,本章节提供TensorFlow集成KTFOP的方法。
1 | git clone -b v1.0.0 https://gitee.com/openeuler/sra_tensorflow_adapter.git |
1 | cd sra_tensorflow_adapter |
1 2 3 4 5 6 | pip3 install wheel pip3 install Cython==0.29.14 pip3 install numpy==1.18.5 --no-build-isolation pip3 install h5py==2.10.0 pip3 install protobuf==3.19.0 pip3 install keras_preprocessing==1.1.2 |
1 2 3 | export PATH=/path/to/bazel/bazel-0.26.1/output:$PATH export PATH=/usr/local/python3.7.5/bin:$PATH export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib:$LD_LIBRARY_PATH |
1 | sh build.sh
|
Tensorflow whl包路径为:“out/tensorflow-1.15.0-cp37-cp37m-linux_aarch64.whl”
用户可根据需要,设置KBLAS_LIB_DIR环境变量,自行选择KML_BLAS库编译。例如,使用数学库KML 2.5版本使能NEON特性的BLAS库:
1 | export KBLAS_LIB_DIR=/usr/local/kml/lib/neon/kblas/locking |
1 | pip3 install out/tensorflow-1.15.0-cp37-cp37m-linux_aarch64.whl |
TensorFlow 1.15.0编译安装完成后使用自带样例进行基本功能的验证。本文使用自带样例中的图像识别样例来验证TensorFlow的基本功能。
1 | python3 -c "import tensorflow as tf; print(tf.__version__)" |
回显信息显示,版本号为1.15.0。
1 | cd /path/to/sra_tensorflow_adapter |
1 2 | curl -L "https://storage.googleapis.com/download.tensorflow.org/models/inception_v3_2016_08_28_frozen.pb.tar.gz" | tar -C tensorflow/examples/label_image/data -xz wget -P tensorflow/examples/label_image/data/ https://www.tensorflow.org/images/cropped_panda.jpg --no-check-certificate |
1 | python3 tensorflow/examples/label_image/label_image.py --image=tensorflow/examples/label_image/data/cropped_panda.jpg |
回显信息显示,将图片“tensorflow/examples/label_image/data/cropped_panda.jpg”识别为giant panda类别的概率最大。