TensorFlow in Go

TensorFlow in Go

Construct and execute TensorFlow graphs in Go.

GoDoc

WARNING: The API defined in this package is not stable and can change without notice. The same goes for the awkward package path (github.com/tensorflow/tensorflow/tensorflow/go).

Quickstart

  1. Download and extract the TensorFlow C library, preferably into/usr/local. GPU-enabled versions require CUDA 8.0 and cuDNN 5.1. For other versions, the TensorFlow C library will have to be built from source (see below).

    The following shell snippet downloads and extracts into/usr/local:

    TF_TYPE="cpu" # Set to "gpu" for GPU support
    curl -L \
      "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-${TF_TYPE}-$(go env GOOS)-x86_64-1.0.0.tar.gz" |
    sudo tar -C /usr/local -xz
    
  2. go getthis package (and run tests):

    go get github.com/tensorflow/tensorflow/tensorflow/go
    go test github.com/tensorflow/tensorflow/tensorflow/go
    
  3. Done!

 Installing into locations other than/usr/local

The TensorFlow C library (libtensorflow.so) needs to be available at build time (e.g.,go build) and run time (go testor executing binaries). If the library has not been extracted into/usr/local, then it needs to be made available through theLIBRARY_PATHenvironment variable at build time and theLD_LIBRARY_PATHenvironment variable (DYLD_LIBRARY_PATHon OS X) at run time.

For example, if the TensorFlow C library was extracted into/dir, then:

export LIBRARY_PATH=/dir/lib
export LD_LIBRARY_PATH=/dir/lib   # For Linux
export DYLD_LIBRARY_PATH=/dir/lib # For OS X

Building the TensorFlow C library from source

If the "Quickstart" instructions above do not work (perhaps the release archives are not available for your operating system or architecture, or you're using a different version of CUDA/cuDNN), then the TensorFlow C library must be built from source.

 Prerequisites

  • bazel
  • Environment to build TensorFlow from source code (Linux or OS X). If you don't need GPU support, then try the following:sh # Linux sudoapt-get install python swig python-numpy # OS X with homebrew brew installswig

 Build

  1. Download the source code

    go get -d github.com/tensorflow/tensorflow/tensorflow/go
    
  2. Build the TensorFlow C library:

    cd ${GOPATH}/src/github.com/tensorflow/tensorflow
    ./configure
    bazel build --config opt //tensorflow:libtensorflow.so
    

    This can take a while (tens of minutes, more if also building for GPU).

  3. Makelibtensorflow.soavailable to the linker. This can be done by either:

    a. Copying it to a system location, e.g.,

    sudo cp ${GOPATH}/src/github.com/tensorflow/tensorflow/bazel-bin/tensorflow/libtensorflow.so /usr/local/lib
    

    OR

    b. Setting environment variables:

    export LIBRARY_PATH=${GOPATH}/src/github.com/tensorflow/tensorflow/bazel-bin/tensorflow
    # Linux
    export LD_LIBRARY_PATH=${GOPATH}/src/github.com/tensorflow/tensorflow/bazel-bin/tensorflow
    # OS X
    export DYLD_LIBRARY_PATH=${GOPATH}/src/github.com/tensorflow/tensorflow/bazel-bin/tensorflow
    
  4. Build and test:

    go test github.com/tensorflow/tensorflow/tensorflow/go
    

 Generate wrapper functions for ops

Go functions corresponding to TensorFlow operations are generated inop/wrappers.go. To regenerate them:

Prerequisites:

go generate github.com/tensorflow/tensorflow/tensorflow/go/op

Support

Use stackoverflow and/or Github issues.

Contributions

Contributions are welcome. If making any signification changes, probably best to discuss on a Github issue before investing too much time. Github pull requests are used for contributions.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值