dsznndq4912405 2019-05-21 08:51
浏览 292

在Golang上进行Tensorflow部分运行(RNN状态)

I have a GRU RNN text generation model that I imported as protobuf in Golang.

model, err := tf.LoadSavedModel("poetryModel", []string{"goTag"}, nil)

Similar to the code from this Tensorflow tutorial, I am running a prediction loop:

for len(generated_text) < 1000 {
    result, err := model.Session.Run(
            map[tf.Output]*tf.Tensor{
                model.Graph.Operation("inputLayer_input").Output(0): tensor,
            },
            []tf.Output{
                model.Graph.Operation("outputLayer/add").Output(0),
            },
            nil,
        )
    ...}

However, this implementation discards all intermediate states after every loop which results in bad generated text. I tried using Partial Run, but it threw an error at the second Run:

pr, err := model.Session.NewPartialRun(
    []tf.Output{ model.Graph.Operation("inputLayer_input").Output(0), },
    []tf.Output{ model.Graph.Operation("outputLayer/add").Output(0), },
    []*tf.Operation{ model.Graph.Operation("outputLayer/add") },
)
if err != nil {
    panic(err)
}

...

result, err := pr.Run(
        map[tf.Output]*tf.Tensor{
            model.Graph.Operation("inputLayer_input").Output(0): tensor,
        },
        []tf.Output{
            model.Graph.Operation("outputLayer/add").Output(0),
        },
        nil,
    )

Error running the session with input, err: Must run 'setup' before performing partial runs!

This question is similar to this one, but in Python. Also, there is no documentation of a setup function in Go. I am new to working directly with the TF computation graph and Golang, so any help is appreciated.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 matlab求解平差
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制
    • ¥20 usb设备兼容性问题
    • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
    • ¥15 安装svn网络有问题怎么办
    • ¥15 vue2登录调用后端接口如何实现
    • ¥65 永磁型步进电机PID算法
    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?