Skip to content
TensorFlow学习笔记
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
README.md

README.md

easy_tensorflow

TensorFlow学习笔记


1. 安装

1.1 ubuntu安装

1.2 Mac OS安装

TensorFlow Python API 依赖 Python 2.7 版本

brew install python2.7
pip install https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl

1.3 使用容器VirtualEnv安装

推荐使用 virtualenv 创建一个隔离的容器, 来安装 TensorFlow. 这样做能使排查安装问题变得更容易

# 在 Mac 上:
sudo easy_install pip  # 如果还没有安装 pip
sudo pip install --upgrade virtualenv
  • 建立一个全新的 virtualenv 环境,将环境建在 ~/tensorflow 目录下

    virtualenv --system-site-packages ~/tensorflow
    cd ~/tensorflow
    
  • 激活 virtualenv

    source bin/activate  # 如果使用 bash
    source bin/activate.csh  # 如果使用 csh
    (tensorflow)$  # 终端提示符应该发生变化
    
  • 在 virtualenv 内, 安装 TensorFlow

    (tensorflow)$ pip install --upgrade <$url_to_binary.whl>
    
    <$url_to_binary.whl>选择:
    # Mac只支持 CPU
    https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl
    # Linux只支持 CPU
    https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl
    # 开启 GPU 支持的版本 (安装该版本的前提是已经安装了 CUDA sdk)
    https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl
    
  • 运行 TensorFlow 程序

    (tensorflow)$ cd tensorflow/models/image/mnist
    (tensorflow)$ python convolutional.py
    

    or

    python
    import tensorflow as tf
    hello = tf.constant('Hello, TensorFlow!')
    sess = tf.Session()
    print sess.run(hello)
    Hello, TensorFlow!
    
  • 当使用完 TensorFlow

    # 停用 virtualenv
    (tensorflow)$ deactivate
    

1.4 从源码安装

  • clone TensorFlow 仓库

    # --recurse-submodules 参数是必须得, 用于获取 TesorFlow 依赖的 protobuf 库
    git clone --recurse-submodules https://github.com/tensorflow/tensorflow
    
  • Mac OS安装
    所需依赖:Bazel, SWIG

    brew install bazel
    brew install swig
    

2. 栗子

2.1 For Java

example

JDK1.7

  • Start Using Apache Maven

    • 创建Maven工程

    • 添加依赖

      <dependencies>
        <dependency>
          <groupId>org.tensorflow</groupId>
          <artifactId>tensorflow</artifactId>
          <version>1.1.0-rc1</version>
        </dependency>
      </dependencies>
      
    • 下载样例代码添加至src/main/java/org/tensorflow/examples

      mkdir -p src/main/java/org/tensorflow/examples
      curl -L "https://raw.githubusercontent.com/tensorflow/tensorflow/master/tensorflow/java/src/main/java/org/tensorflow/examples/LabelImage.java" -o src/main/java/org/tensorflow/examples/LabelImage.java
      
    • 编译

      mvn compile exec:java
      
  • Start Using java and javac

2.2 Python Example

You can’t perform that action at this time.