Golang Model sessionn上的Tensorflow运行错误:nil-Operation。 如果输出是使用Scope对象创建的,请参见Scope.Err()了解详细信息

问题描述:

iam use golang with tensorflow model. With this code : ```

    output, err := sessionModel.Run(
    map[tf.Output]*tf.Tensor{
        graphModel.Operation("input").Output(0): tensor,
    },
    []tf.Output{
        graphModel.Operation("output").Output(0),
    },
    nil)

```

But show error : 2019/01/07 18:07:48 http: panic serving [::1]:55262: nil-Operation. If the Output was created with a Scope object, see Scope.Err() for details.

I am already check tensor contain tensor from image file. Any recomendation ? Thanks anyway

iam将golang与tensorflow模型一起使用。 使用以下代码: ``` p>

 输出,err:= sessionModel.Run(
 map [tf.Output] * tf.Tensor {
 graphModel.Operation  (“ input”)。Output(0):张量,
},
 [] tf.Output {
 graphModel.Operation(“ output”)。Output(0),
},
 nil)\  n  code>  pre> 
 
 

``` p>

但是显示错误: 2019 / 01/07 18:07:48 http:紧急服务[:: 1]:55262:无操作。 如果使用Scope对象创建了Output,请参见Scope.Err()了解详细信息。 code> p>

我已经在检查 tensor code>包含张量了 来自图像文件。 任何建议吗? 还是要谢谢 p> div>

The error says the Output attribute (of a certain the node) is a nil operation.

Hence graphModel.Operation("input").Operation(0) or graphModel.Operation("output").Output(0) returns nil.

To correct this, you have to refer to an existing node in the graph because there's no a tensor named input or a tensor named output in the graph.

From the python code you used to export the model you can find the complete name of your input and output tensors. Just access the .name attribute of your input placeholder and of your output node, to get the correct name to use in Go.

Also, the Go bindings are complex to use, especially if you want to run some preprocessing operations on the input image. I suggest you use galeone/tfgo instead of directly using the bindings (Note that I am the author of this repo).

I would like to add to @nessuno great answer, that I needed to do: my_model.inputs and my_model.outputs to get the proper names. For example:

> my_model.inputs
[<tf.Tensor 'dense_1_input:0' shape=(?, 7) dtype=float32>
> my_model.outputs
[<tf.Tensor 'my_output/BiasAdd:0' shape=(?, 2) dtype=float32>

Therefore, my input and output nodes are dense_1_input and my_output/BiasAdd (not my_output!)