README
Tensorflow Serving client for go
Go client for Tensorflow Serving
Example
Example uses pre-trained model found under testdata/models wide_deep
import "github.com/Applifier/go-tensorflow/serving"
// Init client
cli, _ := serving.NewModelPredictionClientFromAddr(
getServingAddr(),
"wide_deep",
"serving_default",
1527087570,
)
// Create Example and Features
example, _ := serving.NewExampleFromMap(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",
})
// Convert example to protobuf
exampleSerialized, _ := example.Marshal()
// Convert serialized example to tensor
tensor, _ := NewTensor([][]byte{exampleSerialized})
res, _ := cli.Predict(context.Background(), serving.TensorMap{
"inputs": tensor,
}, nil)
fmt.Printf("scores %+v\n", res.Outputs["scores"].FloatVal)
// Output: scores [0.54612064 0.45387936]
Documentation
Overview ¶
Package serving is a client for Tensorflow Serving written in Go
Index ¶
- func NewPredictor(modelClient ModelPredictionClient) predict.Predictor
- func ShapeFromTensor(t *Tensor) []int64
- func ValueFromTensor(t *Tensor) interface{}
- type ModelPredictionClient
- func NewModelPredictionClientFromAddr(serverAddr string, name string, signatureName string) (ModelPredictionClient, error)
- func NewModelPredictionClientFromConn(conn *grpc.ClientConn, name string, signatureName string) ModelPredictionClient
- func NewModelPredictionClientFromPredictionServiceClient(cli serving.PredictionServiceClient, name string, signatureName string) ModelPredictionClient
- type Shape
- type ShapeDim
- type Tensor
- type TensorMap
Examples ¶
Constants ¶
Variables ¶
Functions ¶
func NewPredictor ¶
func NewPredictor(modelClient ModelPredictionClient) predict.Predictor
NewPredictor returns a new predictor (implements Predictor interface) using a given TF Serving client
func ShapeFromTensor ¶
ShapeFromTensor returns shape from a tensor
func ValueFromTensor ¶
func ValueFromTensor(t *Tensor) interface{}
ValueFromTensor returns value from a given tensor
Types ¶
type ModelPredictionClient ¶
type ModelPredictionClient interface { // Classify. Classify(ctx context.Context, input *serving.Input, opts ...grpc.CallOption) (*serving.ClassificationResponse, error) // Regress. Regress(ctx context.Context, input *serving.Input, opts ...grpc.CallOption) (*serving.RegressionResponse, error) // Predict -- provides access to loaded TensorFlow model. Predict(ctx context.Context, inputs TensorMap, outputFilter []string, opts ...grpc.CallOption) (*serving.PredictResponse, error) // GetModelMetadata - provides access to metadata for loaded models. GetModelMetadata(ctx context.Context, opts ...grpc.CallOption) (*serving.GetModelMetadataResponse, error) io.Closer }
ModelPredictionClient represents a prediction client for a single model
Example ¶
Output: scores [0.54612064 0.45387936]
func NewModelPredictionClientFromAddr ¶
func NewModelPredictionClientFromAddr(serverAddr string, name string, signatureName string) (ModelPredictionClient, error)
NewModelPredictionClientFromAddr returns a new client for a given TensorFlow Serving address
func NewModelPredictionClientFromConn ¶
func NewModelPredictionClientFromConn(conn *grpc.ClientConn, name string, signatureName string) ModelPredictionClient
NewModelPredictionClientFromConn returns a new client from a GRPC client connection
func NewModelPredictionClientFromPredictionServiceClient ¶
func NewModelPredictionClientFromPredictionServiceClient(cli serving.PredictionServiceClient, name string, signatureName string) ModelPredictionClient
NewModelPredictionClientFromPredictionServiceClient returns a new client from a serving PredictionServiceClient
type Tensor ¶
type Tensor = framework.TensorProto
Tensor a tensorflow tensor
func NewTensorWithShape ¶
NewTensorWithShape returns a tensor with a specific shape