Skip to content

wamuir/graft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

e77c556 · Mar 15, 2025
Jan 11, 2025
Feb 17, 2025
Mar 15, 2025
Mar 1, 2025
Jan 11, 2025
Jan 11, 2025
Feb 17, 2025
Apr 6, 2024
Dec 11, 2021
Feb 17, 2025
Oct 31, 2023
Feb 17, 2025
Feb 17, 2025

Repository files navigation

Graft

tensorflow version nightly go.dev reference

About

Go language bindings to the TensorFlow C API

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.

Use Graft exactly as you would use the Go bindings found in the main TensorFlow repo, and with the following import statement: github.com/wamuir/graft/tensorflow

Getting Started

Note: the Go bindings depend on libtensorflow, which should be downloaded (or compiled) and installed first.

Installation is performed using go get:

go get -u github.com/wamuir/graft/tensorflow/...
Hello TensorFlow
package main

import (
	tf "github.com/wamuir/graft/tensorflow"
	"github.com/wamuir/graft/tensorflow/op"
	"fmt"
)

func main() {
	// Construct a graph with an operation that produces a string constant.
	s := op.NewScope()
	c := op.Const(s, "Hello from TensorFlow version " + tf.Version())
	graph, err := s.Finalize()
	if err != nil {
		panic(err)
	}

	// Execute the graph in a session.
	sess, err := tf.NewSession(graph, nil)
	if err != nil {
		panic(err)
	}
	output, err := sess.Run(nil, []tf.Output{c}, nil)
	if err != nil {
		panic(err)
	}
	fmt.Println(output[0].Value())
}

Credits

Graft is a compilation of TensorFlow source code.