Code Monkey home page Code Monkey logo

Comments (5)

yohaiaz avatar yohaiaz commented on July 20, 2024 1

Thanks a lot to @galeone
it's working now for me
hope for a "go get"-able tensorflow stable go api

from tfgo.

galeone avatar galeone commented on July 20, 2024

The tensorflow Go package is not a standard Go package, in fact you have to manually download it by your self and switch to the correct branch of the repository.

Have a look at how I do this in the .travis.yml:

git clone https://github.com/tensorflow/tensorflow $GOPATH/src/github.com/tensorflow/tensorflow/
pushd $GOPATH/src/github.com/tensorflow/tensorflow/tensorflow/go
git checkout r1.14
go build

Let me know if it works for you

from tfgo.

yohaiaz avatar yohaiaz commented on July 20, 2024

thanks you so much @galeone
I don't really understand the purposes of the 3 last command line you specified.
I'm trying to work in the same way I'm working with other dependencies.

after running the following line i'm getting the sources at my go path.
git clone https://github.com/tensorflow/tensorflow $GOPATH/src/github.com/tensorflow/tensorflow/

now i can import it like this:
import (
tensorflow "github.com/tensorflow/tensorflow/tensorflow/go"
"github.com/tensorflow/tensorflow/tensorflow/go/op"
)

running the following function give me the error like this

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

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

}

error ===>
../../tensorflow/tensorflow/tensorflow/go/saved_model.go:25:2: cannot find package "github.com/tensorflow/tensorflow/tensorflow/go/genop/internal/proto/github.com/tensorflow/tensorflow/tensorflow/go/core" in any of:

/usr/local/Cellar/go/1.13.4/libexec/src/github.com/tensorflow/tensorflow/tensorflow/go/genop/internal/proto/github.com/tensorflow/tensorflow/tensorflow/go/core (from $GOROOT)
/Users/yohai/dev/go/src/github.com/tensorflow/tensorflow/tensorflow/go/genop/internal/proto/github.com/tensorflow/tensorflow/tensorflow/go/core (from $GOPATH)

from tfgo.

yohaiaz avatar yohaiaz commented on July 20, 2024

also ... a lot of tutorials and post specify running this 2 lines
go get github.com/tensorflow/tensorflow/tensorflow/go
go test github.com/tensorflow/tensorflow/tensorflow/go

this is exactly how I import go packages for use in my code but something going wrong

there is also an opened issue https://github.com/tensorflow/tensorflow/issues/34580 and no one is correcting the issue.

Or maybe I'm missing something ?

from tfgo.

galeone avatar galeone commented on July 20, 2024

A lot of tutorials do the wrong assumption that the master branch of the TensorFlow repo has a stable Go API. This is false.

The go get command, simply clones the tensorflow repository in your go path and checks it out to the master branch; but the master branch is not stable for Go :)

So, you have to manually checkout to a branch that has a stable Go API. In the lines above I did it:

  1. git clone https://github.com/tensorflow/tensorflow $GOPATH/src/github.com/tensorflow/tensorflow/: I'm cloning the tensorflow repo into the correct path (this is equivalent to the go get command)
  2. pushd $GOPATH/src/github.com/tensorflow/tensorflow/tensorflow/go I'm changing dir and going into the go package, inside the tensorflow repo I just cloned
  3. git checkout r1.14 I'm changing branch, from master (unstable) to r1.14 (tensorflow 1.14) that has a stable and working Go API.
  4. go build I'm building the go package from sources
  5. go test If you want to be sure that everything works, run go test (inside the same folder) to test the tensorflow/go package

from tfgo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.