提交 4c5418f9 编写于 作者: G guru4elephant

add general model config

上级 8c466b81
...@@ -22,6 +22,7 @@ import ( ...@@ -22,6 +22,7 @@ import (
"net/http" "net/http"
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"general_model_config"
) )
type Tensor struct { type Tensor struct {
...@@ -47,6 +48,16 @@ type Response struct { ...@@ -47,6 +48,16 @@ type Response struct {
Insts []FetchInst `json:"insts"` Insts []FetchInst `json:"insts"`
} }
type Handle struct {
Url string
Port int
FeedAliasNameMap Map[string]string
FeedShapeMap Map[string][]int
FeedNameMap Map[string]int
FetchNameMap Map[string]int
FetchAliasNameMap Map[string]string
}
func LoadModelConfig(config string) Handle { func LoadModelConfig(config string) Handle {
in, err := ioutil.ReadFile(config) in, err := ioutil.ReadFile(config)
if err != nil { if err != nil {
...@@ -56,19 +67,40 @@ func LoadModelConfig(config string) Handle { ...@@ -56,19 +67,40 @@ func LoadModelConfig(config string) Handle {
if err := proto.Unmarshal(in, general_model_config); err != nil { if err := proto.Unmarshal(in, general_model_config); err != nil {
log.Fatalln("Failed to parse GeneralConfig: ", err) log.Fatalln("Failed to parse GeneralConfig: ", err)
} }
fmt.Println("Read message done.") handle := Handle{}
for i, v in range general_model_config.FeedVar {
handle.FeedNameMap[v.Name] = i
handle.FeedShapeMap[v.Name] = v
handle.FeedAliasNameMap[v.AliasName] = v.Name
}
for i, v in range general_model_config.FetchVar {
handle.FetchNameMap[v.Name] = i
handle.FetchAliasNameMap[v.AliasName] = v.Name
}
return handle
} }
func Connect(url string, port int, handle Handle) { func Connect(url string, port int, handle Handle) Handle {
handle.Url = url handle.Url = url
handle.Port = port handle.Port = port
return handle
} }
func Predict(handle Handle, int_feed_map Map[string]int[], func Predict(handle Handle, int_feed_map Map[string]int{}, fetch []string) {
float_feed_map Map[string]float[], fetch []string) {
contentType := "application/json;charset=utf-8" contentType := "application/json;charset=utf-8"
var tensor_array []Tensor{}
var inst FeedInst var inst FeedInst
for k, v := range int_feed_map {
var tmp Tensor
tmp.Data = int_feed_map[k]
tmp.ElemType = 0
tmp.Shape = handle.FeedNameShape[k]
tensor_array = append(tensor_array, tmp)
}
req := &Request{ req := &Request{
Insts: []FeedInst{inst}, Insts: []FeedInst{inst},
FetchVarNames: []string{fetch}} FetchVarNames: []string{fetch}}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册