机器学习:使用 NVIDIA JetsonTX2 - 安装TensorFlow

优质
小牛编辑
121浏览
2023-12-01

安装 TensorFlow

  1. 安装依赖套件

    1. $ sudo apt-get install default-jdk libcupti-dev
    2. $ export JAVA_HOME='/usr/lib/jvm/java-8-openjdk-arm64/'
  2. 取得 TensorFlow 编译脚本

    1. $ git clone git://github.com/jetsonhacks/installTensorFlowTX2
    2. $ cd installTensorFlowTX2
  3. 执行编译脚本

    1. $ ./installPrerequisitesPy3.sh
    2. $ ./cloneTensorFlow.sh
    3. $ ./setTensorFlowEVPy3.sh
    4. $ ./buildTensorFlow.sh
    5. $ ./packageTensorFlow.sh
  4. 安装 TensorFlow

    1. 建立虚拟开发环境

      1. $ virtualenv TensorFlow
    2. 进入虚拟开发环境

      1. $ cd TensorFlow
      2. $ source bin/active
    3. 安装 TensorFlow 到虚拟环境

      1. pip3 install $HOME/<TensorFlow 的 .whl 安装封包>
    4. 测试 TensorFlow

      1. Hello World

        1. import tensorflow as tf
        2. hello = tf.constant('Hello, TensorFlow on NVIDIA Jetson TX2!')
        3. sess = tf.Session()
        4. print(sess.run(hello))

        输出

        1. Hello, TensorFlow on NVIDIA Jetson TX2!
      2. 运算单元

        1. import tensorflow as tf
        2. # Creates a graph.
        3. a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
        4. b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
        5. c = tf.matmul(a, b)
        6. # Creates a session with log_device_placement set to True.
        7. sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
        8. # Runs the op.
        9. print(sess.run(c))

        输出

        1. name: NVIDIA Tegra X2
        2. major: 6 minor: 2 memoryClockRate (GHz) 1.3005
        3. MatMul: (MatMul): /job:localhost/replica:0/task:0/gpu:0
        4. b: (Const): /job:localhost/replica:0/task:0/gpu:0
        5. a: (Const): /job:localhost/replica:0/task:0/gpu:0
        6. [[ 22. 28.]
        7. [ 49. 64.]]