1
votes
def build_metric(self):
    with tf.variable_scope('fc', reuse=tf.AUTO_REUSE):
      response_m = self.response
      shape = response_m.get_shape().as_list()[1:3]
      output_list = []  
      for i in range(shape[0]):
        for j in range(shape[1]):
          t1 = self.instance_embeds[:,i:i+6,j:j+6,:]
          t2 = self.templates
          t1, t2 = logit(t1, t2)
          f = gsml(t1, t2)
          for s in range(8):
            response_m[s, i, j] = f[s]
          output_list.append(f)
      self.response_m = response_m

response_m[s, i, j] = f[s]

TypeError: 'Tensor' object does not support item assignment

what can I do?

1
self.response is a variable tensor??? - Inder

1 Answers

0
votes

Assuming that your response variable is a tensorflow variable:

You can use assing for this purpose:

def build_metric(self):
    with tf.variable_scope('fc', reuse=tf.AUTO_REUSE):
      response_m = self.response
      shape = response_m.get_shape().as_list()[1:3]
      output_list = []  
      for i in range(shape[0]):
        for j in range(shape[1]):
          t1 = self.instance_embeds[:,i:i+6,j:j+6,:]
          t2 = self.templates
          t1, t2 = logit(t1, t2)
          f = gsml(t1, t2)
          for s in range(8):
            response_m=tf.assign(response[s,i,j],f[s]) #change I have made

          output_list.append(f)
      self.response_m = response_m

A simpler example for understanding can be:

one=tf.Variable(tf.zeros(shape=[1,10]))
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(sess.run(one),"\n")

new_one=tf.assign(one[0,2],0.33) #using index to assign values
with tf.Session() as sess_2:
    sess_2.run(tf.global_variables_initializer()) #initialize variables with zero values
    print(sess_2.run(new_one))

The output of the code will be:

[[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]] 

[[0.   0.   0.33 0.   0.   0.   0.   0.   0.   0.  ]]