Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Tensorflow + Go, the gopher way
| Date | Stars |
|---|---|
| 2026-07-24 | 2492 |
| 2026-07-25 | 2492 |
| 2026-07-28 | 2492 |
| 2026-07-30 | 2492 |
| 2026-08-06 | 2492 |
Today
— stars today
This week
— stars this week
This month
— stars this month
Momentum
0.0
growth rate 0.00%/day
# tfgo: TensorFlow in Go
[](https://godoc.org/github.com/galeone/tfgo)
[](https://travis-ci.org/galeone/tfgo)
---
- [tfgo: TensorFlow in Go](#tfgo-tensorflow-in-go)
- [Dependencies](#dependencies)
- [Installation](#installation)
- [Getting started](#getting-started)
- [Computer Vision using data flow graph](#computer-vision-using-data-flow-graph)
- [Train in Python, Serve in Go](#train-in-python-serve-in-go)
- [Python code](#python-code)
- [Go code](#go-code)
- [Why?](#why)
- [Contribute](#contribute)
- [TensorFlow installation](#tensorflow-installation)
- [Manual](#manual)
- [Docker](#docker)
TensorFlow's Go bindings are [hard to use](https://pgaleone.eu/tensorflow/go/2017/05/29/understanding-tensorflow-using-go/): tfgo makes it easy!
No more problems like:
- Scoping: each new node will have a new and unique name
- Typing: attributes are automatically converted to a supported type instead of throwing errors at runtime
Also, it uses [Method chaining](https://en.wikipedia.org/wiki/Method_chaining) making possible to write pleasant Go code.
## Dependencies
1. TensorFlow-2.9.1 lib. [How to install tensorflow](#tensorflow-installation).
2. TensorFlow bindings github.com/galeone/tensorflow. In order to correctly work with TensorFlow 2.9.1 in Go, we have to use a fork I created with some fix for the Go bindings. Bindings can be too large for go mod proxy, so you may want to switch off proxy usage by executing `go env -w GONOSUMDB="github.com/galeone/tensorflow"` to pull code directly using system installed git. It changes nothing in the user interface -- you can use go modules as usual.
## Installation
```
go get github.com/galeone/tfgo
```
## Getting started
The core data structure of the TensorFlow's Go bindings is the `op.Scope` struct. tfgo allows creating new `*op.Scope` that solves the scoping issue mentioned above.
Since we're defining a graph, let's start from its root (empty graph)
```go
root := tg.NewRoot()
```
We can now place nodes into this graphs and connect them. Let's say we want to multiply a matrix for a column vector and then add another column vector to the result.
Here's the complete source code.
```go
package main
import (
"fmt"
tg "github.com/galeone/tfgo"
tf "github.com/galeone/tensorflow/tensorflow/go"
)
func main() {
root := tg.NewRoot()
A := tg.NewTensor(root, tg.Const(root, [2][2]int32{{1, 2}, {-1, -2}}))
x := tg.NewTensor(root, tg.Const(root, [2][1]int64{{10}, {100}}))
b := tg.NewTensor(root, tg.Const(root, [2][1]int32{{-10}, {10}}))
Y := A.MatMul(x.Output).Add(b.Output)
// Please note that Y is just a pointer to A!
// If we want to create a different node in the graph, we have to clone Y
// or equivalently A
Z := A.Clone()
results := tg.Exec(root, []tf.Output{Y.Output, Z.Output}, nil, &tf.SessionOptions{})
fmt.Println("Y: ", results[0].Value(), "Z: ", results[1].Value())
fmt.Println("Y == A", Y == A) // ==> true
fmt.Println("Z == A", Z == A) // ==> false
}
```
that produces
```
Y: [[200] [-200]] Z: [[200] [-200]]
Y == A true
Z == A false
```
The list of the available methods is available on GoDoc: http://godoc.org/github.com/galeone/tfgo
## Computer Vision using data flow graph
TensorFlow is rich of methods for performing operations on images. tfgo provides the `image` package that allows using the Go bindings to perform computer vision tasks in an elegant way.
For instance, it's possible to read an image, compute its directional derivative along the horizontal and vertical directions, compute the gradient and save it.
The code below does that, showing the different results achieved using correlation and convolution operations.
```go
package main
import (
tg "github.com/galeone/tfExcerpt of 10,396 characters
Read on GitHubWould you bet a product on this? Bounded 0–100 and slow moving.
matched fp:2b07e03fa6631be7, topic:tensorflow