打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
基于openeuler aarch_64 下,从源码的角度搭建Tensorflow

为什么从源码编译Tensorflow?

  • 安装过的人们都知道如果

    pip install tensorflow

的话会报错Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

  • 考虑到操作系统的的兼容性,现有的编译好的二进制安装包不适用openeuler,所以考虑这些因素,我们要自己搭建。

  • 我们需要bazel交叉编译软件,有点类似cmake(上游下载的开源.sh文件已上传到仓库)bazel下载地址

  • chmod +x bazel-0.28.0-installer-linux-x86_64.sh

  • ./bazel-0.28.0-installer-linux-x86_64.sh --user

  • bazel version查看版本,configure.py查看tf所支持的版本(2.3版本所支持的bazel)

_TF_MIN_BAZEL_VERSION = '0.27.1'

_TF_MAX_BAZEL_VERSION = '0.29.1'

下载TF

  • git clone https://github.com/tensorflow/tensorflow
  • git barach -a 查看所有发行版本
  • git checkout <version> 将分支同步到本地

开始编译

  • bazel build --config=opt --config=cuda //tensorflow:libtensorflow_cc.so(C文件库)

  • bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package(wheel文件)

  • bazel build --config=opt --config=cuda //tensorflow:libtensorflow.so(生成C库)

  • bazel build --config=opt //tensorflow/lite:libtensorflowlite.so (Lite库)

bazel编译有的时候会出issue现bug,详见issue

openeuler搭建Bulid Not Successfully 的Bug情况汇总

源码编译链接

官网上说安装需要pip19以上

关于openeulerpip源默认指向python2该如何修改:

#!/usr/bin/python2=====>!/usr/bin/python3
  
# -*- coding: utf-8 -*-
import re
import sys

from pip._internal.cli.main import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

2、修改默认指向由于版本不同所发生的bug

 from pip import main
ImportError: cannot import name 'main' from 'pip' (/usr/lib/python3.7/site-packages/pip/__init__.py)

source code change to this

from pip import __main__  //这行也要修改
if __name__ == '__main__':  
    sys.exit(__main__._main())//增加__main__._

PRODUCT

[root@openeuler lzb]# pip -V
pip 20.1.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

安装 TensorFlow pip 软件包依赖项(如果使用虚拟环境,请省略 --user 参数):

pip install -U --user pip six numpy wheel setuptools mock 'future>=0.17.1'
pip install -U --user keras_applications --no-deps
pip install -U --user keras_preprocessing --no-deps 

setup.py

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Ubuntu 16.04 安装 Tensorflow(GPU支持)
从零开始使用tensorflow(1)
win7下tensorflow的安装
DeepMind开源Sonnet:可在TensorFlow中快速构建神经网络
安装Tensorflow(Linux ubuntu)
TensorFlow入门:Ubuntu 配置 TensorFlow
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服