Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/datainq/go-mnist-client
TensorFlow serving mnist example client in Go.
https://github.com/datainq/go-mnist-client
go golang grpc tensorflow tensorflow-examples tensorflow-tutorials
Last synced: 4 months ago
JSON representation
TensorFlow serving mnist example client in Go.
- Host: GitHub
- URL: https://github.com/datainq/go-mnist-client
- Owner: datainq
- License: apache-2.0
- Created: 2018-01-16T18:18:11.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-22T06:35:34.000Z (about 7 years ago)
- Last Synced: 2024-09-28T10:04:11.465Z (4 months ago)
- Topics: go, golang, grpc, tensorflow, tensorflow-examples, tensorflow-tutorials
- Language: Go
- Size: 103 KB
- Stars: 17
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-mnist-client
An example of tensorflow_serving client in Go.
It demonstrates how to connect to the `tensorflow_model_server` launched
as described in
[Serving a TensorFlow Model](https://www.tensorflow.org/serving/serving_basic) on
TensorFlow documentation webpage.The main problem with tensorflow_serving is a lack of Go package ready to
import and run.This example is based on:
[github.com/tobegit3hub/tensorflow_template_application](https://github.com/tobegit3hub/tensorflow_template_application)## Setup fake workspace through a`$GOPATH` or copy files
For a convenience, I provide the generated files under the `gopath`
subdirectory. You can copy files directly to your `$GOPATH`.```bash
cp gopath/src $GOPATH
```## Generating from sources
For a purpose of generating proto we will use a `docker` container `grpc/go` with
`protoc`, `go` and [`gRPC`](https://grpc.io/) protoc extension installed.Remember that a version of TensorFlow Serving, TensorFlow C++ library and
and Go TensorFlow library versions should match.```
go get -u golang.org/x/net/context
go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
go get -u google.golang.org/grpc
go get -u github.com/tensorflow/tensorflow/tensorflow/go
go get -u go.uber.org/ratelimit
```Let's start a docker container mounting a fake gopath:
```bash
docker run --rm -it -v $PWD/gopath:/gopath:ro -v $PWD/gen:/gen grpc/go /bin/bash
```
and copy paste:
```
export GOPATH=/gopathgit clone https://github.com/tensorflow/serving
git clone https://github.com/tensorflow/tensorflowIN=$PWD
OUT=/gen
protoc -I=$IN/serving -I $IN/tensorflow \
--go_out=plugins=grpc:$OUT \
$IN/serving/tensorflow_serving/apis/*.protoIN=$PWD/tensorflow
protoc -I=$IN --go_out=plugins=grpc:$OUT \
$IN/tensorflow/core/framework/*.proto
protoc -I=$IN --go_out=plugins=grpc:$OUT \
$IN/tensorflow/core/protobuf/{saver,meta_graph}.proto
protoc -I=$IN --go_out=plugins=grpc:$OUT \
$IN/tensorflow/core/example/*.proto
```In most cases we have to fix permissions:
```bash
sudo chown -R $USER.$USER gen
```Most of the tensorflow_serving and tensorflow is not prepared to be
imported in go directly, therefore we must **fix incorrect import paths**:```
grep -rl '"tensorflow/' --include \*.go gen |
xargs sed -i 's/"tensorflow\//"github.com\/tensorflow\/tensorflow\/tensorflow\/go\//g'
```And now we need to copy files into the GOPATH:
```bash
mkdir -p $GOPATH/src/github.com/tensorflow/serving
cp -R gen/tensorflow_serving $GOPATH/src/github.com/tensorflow/serving/
mkdir -p $GOPATH/src/github.com/tensorflow/tensorflow/tensorflow/go/
cp -R gen/tensorflow/core $GOPATH/src/github.com/tensorflow/tensorflow/tensorflow/go/
```