1
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??? Commented Mar 8, 2019 at 13:04

1 Answer 1

0

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.  ]]
Sign up to request clarification or add additional context in comments.

1 Comment

@ahuxyy_1 not sure I follow what you are trying to say kindly consider adding in question if this is a code and explain what is the issue with the suggestions I have made

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.