code: def do_tf_sample(session, data, in_states, num_samples):
      """Sampled from the model"""
      samples = []
      sample = None
      # Cell inputs c and h should be passed for each layer explicitly.
      state_input_name = [
          "Model/MultiRNNCellZeroState/LSTMBlockCellZeroState/zeros:0",
          "Model/MultiRNNCellZeroState/LSTMBlockCellZeroState/zeros_1:0",
          "Model/MultiRNNCellZeroState/LSTMBlockCellZeroState_1/zeros:0",
          "Model/MultiRNNCellZeroState/LSTMBlockCellZeroState_1/zeros_1:0",
      ]
      state = in_states
  
      # Graph nodes to be fetched as run output. Tensorflow LSTMBlockCell create internal
      # nodes for intermediate operations (gates) in the cell during run.
      # Cell state (c) is ':1'and cell output (h) is ':6' for each layer.
      fetches = [
          [
              "Model/RNN/RNN/multi_rnn_cell/cell_0/lstm_cell/LSTMBlockCell:1",
              "Model/RNN/RNN/multi_rnn_cell/cell_0/lstm_cell/LSTMBlockCell:6",
              "Model/RNN/RNN/multi_rnn_cell/cell_0/lstm_cell/LSTMBlockCell_1:1",
              "Model/RNN/RNN/multi_rnn_cell/cell_0/lstm_cell/LSTMBlockCell_1:6",
          ],
          "Model/Softmax:0",
      ]
  
      def _get_feed_dict(input_name, input_data):
          """Create feed dict"""
          feed_dict = {}
          if isinstance(input_data, list):
              for i, e in enumerate(input_name):
                  feed_dict[e] = input_data[i]
          else:
              feed_dict[input_name] = input_data
          return feed_dict
  
      for x in data:
          feed_dict = _get_feed_dict(state_input_name, state)
          feed_dict["Model/Placeholder:0"] = [[x]]
          state, probs = session.run(fetches, feed_dict)
          sample = pick_from_weight(probs[0])
      if sample is not None:
          samples.append(sample)
      else:
          samples.append(0)
  
      k = 1
      while k < num_samples:
          feed_dict = _get_feed_dict(state_input_name, state)
          feed_dict["Model/Placeholder:0"] = [[samples[-1]]]
          state, probs = session.run(fetches, feed_dict)
          sample = pick_from_weight(probs[0])
          samples.append(sample)
          k += 1
      return samples, state
  
imports: import re
  import os.path
  import collections
  import numpy
  import tensorflow
  from tensorflow.core.framework import graph_pb2
  import tvm
  from tvm.contrib.download import download_testdata
label_desc: Use image node_id 9 for calling a global function with example usage: do_tf_sample(session, data, in_states, num_samples) and returns: samples,  state, feed_dict