title: Saving TF model trained with keras and then evaluated in Go
body: <p>I'm trying to setup a classical MNIST challenge model with <code>keras</code>, then save the <code>tensorflow</code> graph and subsequently load it in <code>Go</code> and evaluate with some input. I've been following <a href="https://nilsmagnus.github.io/post/go-tensorflow/" rel="nofollow noreferrer">this article</a> which supplies full code on <a href="https://github.com/nilsmagnus/tensorflow-with-go" rel="nofollow noreferrer">github</a>. Nils is using just tensorflow to setup the comp.graph but I would like to use <code>keras</code>. I managd to save the model the same way as he does </p>
  
  <p>model:</p>
  
  <pre><code>   model = Sequential()
  model.add(Conv2D(32, kernel_size=(3, 3),
                   activation='relu',
                   input_shape=(28,28,1), name="inputNode"))
  model.add(Conv2D(64, (3, 3), activation='relu'))
  model.add(MaxPooling2D(pool_size=(2, 2)))
  model.add(Dropout(0.25))
  model.add(Flatten())
  model.add(Dense(128, activation='relu'))
  model.add(Dropout(0.5))
  model.add(Dense(10, activation='softmax', name="inferNode"))
  </code></pre>
  
  <p>which runs ok, trains and evaluates and then saving as posted above:</p>
  
  <pre><code>builder = tf.saved_model.builder.SavedModelBuilder("mnistmodel_my")
  # GOLANG note that we must tag our model so that we can retrieve it at inference-time
  builder.add_meta_graph_and_variables(sess, ["serve"])
  builder.save()
  </code></pre>
  
  <p>Which I then try to evaluate as :</p>
  
  <pre><code>result, runErr := model.Session.Run(
          map[tf.Output]*tf.Tensor{
              model.Graph.Operation("inputNode").Output(0): tensor,
          },
          []tf.Output{
              model.Graph.Operation("inferNode").Output(0),
          },
          nil,
      )
  </code></pre>
  
  <p>In Go I follow the example but when evaluating, I get:</p>
  
  <pre><code>    panic: nil-Operation. If the Output was created with a Scope object, see Scope.Err() for details.
  
  goroutine 1 [running]:
  github.com/tensorflow/tensorflow/tensorflow/go.Output.c(0x0, 0x0, 0x0, 0x0)
      /Users/air/go/src/github.com/tensorflow/tensorflow/tensorflow/go/operation.go:119 +0xbb
  github.com/tensorflow/tensorflow/tensorflow/go.newCRunArgs(0xc42006e210, 0xc420047ef0, 0x1, 0x1, 0x0, 0x0, 0x0, 0xc4200723c8)
      /Users/air/go/src/github.com/tensorflow/tensorflow/tensorflow/go/session.go:307 +0x22d
  github.com/tensorflow/tensorflow/tensorflow/go.(*Session).Run(0xc420078060, 0xc42006e210, 0xc420047ef0, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
      /Users/air/go/src/github.com/tensorflow/tensorflow/tensorflow/go/session.go:85 +0x153
  main.main()
      /Users/air/PycharmProjects/GoTensor/custom.go:36 +0x341
  exit status 2
  </code></pre>
  
  <p>Since it says <code>nil-Operation</code> I think I might have incorrectly labelled the nodes. But I don't know which other nodes should I then label?</p>
  
  <p>Many thanks!!!</p>