go-tensorflow

module
v0.0.0-...-018471a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2020 License: MIT

README

GoDoc Build Status

go-tensorflow

Unified interface for TensorFlow prediction for both embedded models and calls to Tensorflow Serving. Implementations automatically convert go types into matching TensorFlow Tensors.

Models should be exported in the SavedModel format.

Example

Example uses pre-trained model found under testdata/models wide_deep

import "github.com/Applifier/go-tensorflow/savedmodel"
// import "github.com/Applifier/go-tensorflow/serving"

// Uncomment line below to switch implementation
// predictor := serving.NewPredictor(servingModelClient)
predictor, _ := savedmodel.NewPredictor("testdata/models", "wide_deep", 1527087570, "serving_default")


m := map[string]interface{}{
    "age":            35.0,
    "capital_gain":   0.0,
    "capital_loss":   0.0,
    "education":      "Masters",
    "education_num":  14.0,
    "gender":         "Female",
    "hours_per_week": 29.0,
    "native_country": "United-States",
    "occupation":     "Prof-specialty",
    "relationship":   "Husband",
    "workclass":      "Private",
}

res, modelInfo, _ := predictor.Predict(
    context.Background(),
    map[string]interface{}{
        "inputs": m,
    },
    nil,
)

scores := res["scores"].Value().([][]float32)

fmt.Printf("scores %+v\n", scores[0])

// Output: scores [0.54612064 0.45387936]

fmt.Printf("model name %s, version %s", modelInfo.Name, modelInfo.Version)
// Output: model name wide_deep, version 1527087570

License

MIT

Directories

Path Synopsis
examples
internal
Package serving is a client for Tensorflow Serving written in Go
Package serving is a client for Tensorflow Serving written in Go
tools
types

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL