Skip to content
Snippets Groups Projects
Unverified Commit 9f2437c4 authored by William Muir's avatar William Muir Committed by GitHub
Browse files

[Go] Update Go API installation guide for TensorFlow 2.10.0 (#129)

parent 591fc566
Branches
No related tags found
No related merge requests found
...@@ -6,28 +6,57 @@ Maintainer: @wamuir ...@@ -6,28 +6,57 @@ Maintainer: @wamuir
* * * * * *
**Important: TensorFlow for Go is no longer supported by the TensorFlow team.** ## About
# Install TensorFlow for Go
TensorFlow provides a TensorFlow provides a
[Go API](https://pkg.go.dev/github.com/tensorflow/tensorflow/tensorflow/go) [Go API](https://pkg.go.dev/github.com/tensorflow/tensorflow/tensorflow/go)
particularly useful for loading models created with Python and running them particularly useful for loading models created with Python and running them
within a Go application. within a Go application.
Caution: The TensorFlow Go API is *not* covered by the TensorFlow **Important**: TensorFlow for Go is no longer supported by the TensorFlow team.
The TensorFlow Go API is also *not* covered by the TensorFlow
[API stability guarantees](https://www.tensorflow.org/guide/versions). [API stability guarantees](https://www.tensorflow.org/guide/versions).
### Supported Platforms
## Supported Platforms
The Go bindings for TensorFlow work on the following systems, and likely others: The Go bindings for TensorFlow work on the following systems, and likely others:
* Linux, 64-bit, x86 * Linux, 64-bit, x86
* macOS, Version 10.12.6 (Sierra) or higher * macOS, Version 10.12.6 (Sierra) or higher
### Installation
Install the TensorFlow Go API from a community build (compatible with `go get`)
or from source.
## Community Build
> Note: the Go bindings depend on
> [libtensorflow](https://www.tensorflow.org/install/lang_c), which should be
> downloaded (or compiled) and installed first.
A community build, Graft, contains nightly and release builds of the Go
language bindings to the TensorFlow C API, including Go-compiled TensorFlow
protocol buffers and generated Go wrappers for TensorFlow operations. This
community build can be fetched using `go get`.
After installing [libtensorflow](https://www.tensorflow.org/install/lang_c),
use Graft exactly as you would use the Go bindings found in the main TensorFlow
repo, and with one of the following import statements:
| TensorFlow C API | Graft |
| :---------------------------- | :----------------------------------------------------------------------------------------------- |
| TensorFlow Release 2.10.0 | [`go get github.com/wamuir/graft/tensorflow@v0.2.0`](https://github.com/wamuir/graft/tree/r0.2) |
| TensorFlow Release 2.9.2 | [`go get github.com/wamuir/graft/tensorflow@v0.1.1`](https://github.com/wamuir/graft/tree/r0.1) |
| TensorFlow Nightly | [`go get github.com/wamuir/graft/tensorflow@nightly`](https://github.com/wamuir/graft/tree/nightly) |
## Build from Source
## Installation and Setup <details>
<summary>Click to expand</summary>
### 1. Install the TensorFlow C Library ### 1. Install the TensorFlow C Library
...@@ -36,7 +65,7 @@ library is required for use of the TensorFlow Go package at runtime. For example ...@@ -36,7 +65,7 @@ library is required for use of the TensorFlow Go package at runtime. For example
on Linux (64-bit, x86): on Linux (64-bit, x86):
```sh ```sh
$ curl -L https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.9.0.tar.gz | tar xz --directory /usr/local $ curl -L https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.10.0.tar.gz | tar xz --directory /usr/local
$ ldconfig $ ldconfig
``` ```
...@@ -70,11 +99,11 @@ Instead, follow these instructions.*** ...@@ -70,11 +99,11 @@ Instead, follow these instructions.***
$ go env GOPATH $ go env GOPATH
``` ```
- Clone the TensorFlow source respository, substituting the location of your Go - Clone the TensorFlow source repository, substituting the location of your Go
workspace for `/go` in the command below. workspace for `/go` in the command below.
```sh ```sh
$ git clone --branch v2.9.0 https://github.com/tensorflow/tensorflow.git /go/src/github.com/tensorflow/tensorflow $ git clone --branch v2.10.0 https://github.com/tensorflow/tensorflow.git /go/src/github.com/tensorflow/tensorflow
``` ```
- Change the working directory to the base of the cloned TensorFlow repository, - Change the working directory to the base of the cloned TensorFlow repository,
...@@ -121,7 +150,7 @@ workspace for `/go` in the command below: ...@@ -121,7 +150,7 @@ workspace for `/go` in the command below:
```sh ```sh
$ go mod init hello-world $ go mod init hello-world
$ go mod edit -require github.com/tensorflow/tensorflow@v2.9.0+incompatible $ go mod edit -require github.com/tensorflow/tensorflow@v2.10.0+incompatible
$ go mod edit -replace github.com/tensorflow/tensorflow=/go/src/github.com/tensorflow/tensorflow $ go mod edit -replace github.com/tensorflow/tensorflow=/go/src/github.com/tensorflow/tensorflow
$ go mod tidy $ go mod tidy
``` ```
...@@ -167,7 +196,7 @@ func main() { ...@@ -167,7 +196,7 @@ func main() {
```sh ```sh
$ go mod init app $ go mod init app
$ go mod edit -require github.com/tensorflow/tensorflow@v2.9.0+incompatible $ go mod edit -require github.com/tensorflow/tensorflow@v2.10.0+incompatible
$ go mod edit -replace github.com/tensorflow/tensorflow=/go/src/github.com/tensorflow/tensorflow $ go mod edit -replace github.com/tensorflow/tensorflow=/go/src/github.com/tensorflow/tensorflow
$ go mod tidy $ go mod tidy
``` ```
...@@ -195,3 +224,4 @@ following commands: ...@@ -195,3 +224,4 @@ following commands:
$ docker build -t tensorflow/build:golang-example https://github.com/tensorflow/build.git#:golang_install_guide/example-program $ docker build -t tensorflow/build:golang-example https://github.com/tensorflow/build.git#:golang_install_guide/example-program
$ docker run tensorflow/build:golang-example $ docker run tensorflow/build:golang-example
``` ```
</details>
...@@ -14,10 +14,10 @@ ...@@ -14,10 +14,10 @@
# ============================================================================ # ============================================================================
FROM golang:1.18-bullseye FROM golang:1.19-bullseye
# 1. Install the TensorFlow C Library (v2.9.0). # 1. Install the TensorFlow C Library (v2.10.0).
RUN curl -L https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-$(uname -m)-2.9.0.tar.gz \ RUN curl -L https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-$(uname -m)-2.10.0.tar.gz \
| tar xz --directory /usr/local \ | tar xz --directory /usr/local \
&& ldconfig && ldconfig
...@@ -27,7 +27,7 @@ RUN apt-get update && apt-get -y install --no-install-recommends \ ...@@ -27,7 +27,7 @@ RUN apt-get update && apt-get -y install --no-install-recommends \
protobuf-compiler protobuf-compiler
# 3. Install and Setup the TensorFlow Go API. # 3. Install and Setup the TensorFlow Go API.
RUN git clone --branch=v2.9.0 https://github.com/tensorflow/tensorflow.git /go/src/github.com/tensorflow/tensorflow \ RUN git clone --branch=v2.10.0 https://github.com/tensorflow/tensorflow.git /go/src/github.com/tensorflow/tensorflow \
&& cd /go/src/github.com/tensorflow/tensorflow \ && cd /go/src/github.com/tensorflow/tensorflow \
&& go mod init github.com/tensorflow/tensorflow \ && go mod init github.com/tensorflow/tensorflow \
&& (cd tensorflow/go/op && go generate) \ && (cd tensorflow/go/op && go generate) \
...@@ -38,7 +38,7 @@ RUN git clone --branch=v2.9.0 https://github.com/tensorflow/tensorflow.git /go/s ...@@ -38,7 +38,7 @@ RUN git clone --branch=v2.9.0 https://github.com/tensorflow/tensorflow.git /go/s
WORKDIR /example-program WORKDIR /example-program
COPY hello_tf.go . COPY hello_tf.go .
RUN go mod init app \ RUN go mod init app \
&& go mod edit -require github.com/tensorflow/tensorflow@v2.9.0+incompatible \ && go mod edit -require github.com/tensorflow/tensorflow@v2.10.0+incompatible \
&& go mod edit -replace github.com/tensorflow/tensorflow=/go/src/github.com/tensorflow/tensorflow \ && go mod edit -replace github.com/tensorflow/tensorflow=/go/src/github.com/tensorflow/tensorflow \
&& go mod tidy \ && go mod tidy \
&& go build && go build
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment