Applifier / go-tensorflow

Tools and libraries for using Tensorflow (and Tensorflow Serving) in go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Tools and libraries for using Tensorflow (and Tensorflow Serving) in go

License:MIT License


Languages

Language:Go 88.5%Language:Python 6.2%Language:Shell 4.7%Language:Makefile 0.6%