// GetFeatures returns the features corresponding to the given image
GetFeatures returns the features corresponding to the given image
// GetFeatures returns the features corresponding to the given image
func (im ImageModel) GetFeatures(img []byte) ([]float32, error) {
	request := &pb.PredictRequest {
		ModelSpec: &pb.ModelSpec {
			Name:          "resnet18",
			SignatureName: "serving_default",
		},
		Inputs: map[string]*tf.TensorProto {
			"image": &tf.TensorProto {
				Dtype: tf.DataType_DT_STRING,
				TensorShape: &tf.TensorShapeProto {
					Dim: []*tf.TensorShapeProto_Dim {
						&tf.TensorShapeProto_Dim {
							Size: int64(1),
						},
						&tf.TensorShapeProto_Dim {
							Size: int64(1),
						},
					},
				},
				StringVal: [][]byte{img},
			},
		},
	}
	resp, err := im.client.Predict(context.Background(), request)
	if err != nil {
		log.Fatalln(err)
	}
	tp, ok := resp.Outputs["features"]
	if !ok {
		log.Fatalln(err)
	}
	return tp.FloatVal, nil
}
func ( im ImageModel ) GetFeatures ( img [ ] byte ) ( [ ] float32 , error ) { request := & pb . PredictRequest { ModelSpec : & pb . ModelSpec { Name : " " , SignatureName : " " , } , Inputs : map [ string ] * tf . TensorProto { " " : & tf . TensorProto { Dtype : tf . DataType_DT_STRING , TensorShape : & tf . TensorShapeProto { Dim : [ ] * tf . TensorShapeProto_Dim { & tf . TensorShapeProto_Dim { Size : int64 ( 1 ) , } , & tf . TensorShapeProto_Dim { Size : int64 ( 1 ) , } , } , } , StringVal : [ ] [ ] byte { img } , } , } , } resp , err := im . client . Predict ( context . Background ( ) , request ) if err != nil { log . Fatalln ( err ) } tp , ok := resp . Outputs [ " " ] if ! ok { log . Fatalln ( err ) } return tp . FloatVal , nil }
GetFeatures returns the features corresponding to the given image
GetFeatures returns the features corresponding to the given image