title: How to pass a tensor variable to feed_dict?
body: <p>I have basic neural network which has a function run(). which takes the input and provides the output of the neural network. In the function body, I would like to <code>feed_dict</code> weights when running a session to calculate the output. Since these weights are <code>tf.compat.v1.variable</code> I am having an error <code>ValueError: Setting an array element with sequence</code></p>
  
  <p>I have initially thought it was my input that is causing the error and hence, I have made sure it has same dimensions as weights to use <code>tf.multiply</code> and since the error continued, I made sure to convert the numpy array into a tensor object hoping that might be causing the error. But ti still does not work.</p>
  
  <pre class="lang-py prettyprint-override"><code>def run(self, carollis_input):
          self.normalization(carollis_input)
          c_in = np.array(carollis_input)
          c_input = tf.compat.v1.convert_to_tensor(c_in, tf.float64)
          #'finding the output of the input layer'
          #with tf.Session() as sess1_2:
          input_weight = tf.compat.v1.placeholder(tf.float64, shape=(self.neurons, 1))
          input_bias = tf.compat.v1.placeholder(tf.float64, shape=(self.neurons, 1))
          hidden_weight = tf.compat.v1.placeholder(tf.float64, shape=(self.neurons, 1))
          hidden_bias =tf.compat.v1.placeholder(tf.float64, shape=(self.neurons, 1))
          output_weight = tf.compat.v1.placeholder(tf.float64, shape=(4, 1))
          output_bias = tf.compat.v1.placeholder(tf.float64, shape=(self.neurons, 1))
  
          knowledge_input = tf.add(tf.multiply(c_input, input_weight), input_bias)
          with tf.Session() as ses1:
              ses1.run(knowledge_input, feed_dict={input_weight: self.weight_in, input_bias:self.bias_in})
          knowledge_hidden = tf.nn.leaky_relu(knowledge_input, alpha=0.01) 
          #'calculating the output of hidden layer'
          knowledge_hidden_output = 3.14*(tf.add(tf.multiply(knowledge_hidden, hidden_weight), hidden_bias))#input function of hidden layer
          knowledge_hidden_out = tf.nn.leaky_relu(knowledge_hidden_output, alpha=0.01, name='leaky_relu')
  
          with tf.Session() as ses2:
              ses2.run(knowledge_hidden_out, feed_dict={hidden_weight: self.weight_hid, hidden_bias:self.bias_hid})
          #'calculating the input of output layer'
          tf.reshape(knowledge_hidden_out, [4, 2])#for quadrant method
          in_out = tf.add(tf.multiply(knowledge_hidden_out, output_weight), output_bias)
          with tf.Session() as ses3:
              ses3.run(in_out, feed_dict={output_weight: self.weight_out, output_bias: self.bias_out})
          #'finding the softmax output of the neurons'
          softmax_output = np.array(4)
          softmax_output = self.out_softmax(in_out)  # this gives the softmax output and stores it in the newly created array
          return softmax_output
  </code></pre>
  
  <p>After going through other answers , I believe that error might be cause because I was trying to feed in a tensor variable i.e. weights and biases to the feed_dict. If thats the problem, how can i solve it, please kindly help me. The exact error is </p>
  
  <pre><code>File "/home/microbot/catkin_ws/src/spider/spider_control/knowledge_transfer.py", line 85, in run
      ses1.run(knowledge_input, feed_dict={input_weight: self.weight_in, input_bias:self.bias_in})
    File "/home/microbot/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 950, in run
      run_metadata_ptr)
    File "/home/microbot/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1142, in _run
      np_val = np.asarray(subfeed_val, dtype=subfeed_dtype)
    File "/home/microbot/.local/lib/python3.6/site-packages/numpy/core/_asarray.py", line 85, in asarray
      return array(a, dtype, copy=False, order=order)
  ValueError: setting an array element with a sequence
  </code></pre>
  
  <p>EDIT:
  The weights are initialized inside the class initialiser i.e. </p>
  
  <pre><code>def __init__(self, neurons, layers):
          self.neurons = neurons
          self.layers =  layers
          self.weight_initer = tf.truncated_normal_initializer(mean=0.0, stddev=0.01)
          self.weight_in = tf.get_variable(name="Weight_input", dtype=tf.float64, shape=[self.neurons, 1], initializer=self.weight_initer)
          self.weight_initer1 = tf.truncated_normal_initializer(mean=1.0, stddev=0.01)
          self.weight_hid = tf.get_variable(name="Weight_hidden", dtype=tf.float64, shape=[self.neurons, 1], initializer=self.weight_initer1)
          self.weight_initer2 = tf.truncated_normal_initializer(mean=2.0, stddev=0.01)
          self.weight_out = tf.get_variable(name="Weight_output", dtype=tf.float64, shape=[4, 2], initializer=self.weight_initer2)
          self.bias_initer =tf.truncated_normal_initializer(mean=0.1, stddev=0.01)
          self.bias_in  =tf.get_variable(name="Bias_input", dtype=tf.float64, shape=[self.neurons, 1], initializer=self.bias_initer)
          self.bias_initer1 =tf.truncated_normal_initializer(mean=0.2, stddev=0.01)
          self.bias_hid = tf.get_variable(name="Bias_hidden", dtype=tf.float64, shape=[self.neurons, 1], initializer=self.bias_initer1)
          self.bias_initer2 =tf.truncated_normal_initializer(mean=0.3, stddev=0.01)
          self.bias_out = tf.get_variable(name="Bias_output", dtype=tf.float64, shape=[4, 1], initializer=self.bias_initer2)
  
  </code></pre>
  
  <p>Although now I have been having two different confusing, one with respective to scope of the graph and other to the weight initialising. Since I have defined the weight tensors in the initialiser, would this be the defaul graph and the graph that i am trying to build inside the run function be secondary ? </p>