xxx222
xxx222

Reputation: 3244

TypeError: 'Tensor' object does not support item assignment

output = tf.zeros(shape=[2, len(wss), 3, 2*d])
for i, atten_embed in enumerate(atten_embeds):
    for j, ws in enumerate(wss):
        conv_layer = conv_layers_A[j]
        conv = conv_layer(atten_embed)
        new_shape = (reduce(lambda x,y:x*y, conv.get_shape()[:-1]).value,num_filters)
        conv = K.reshape(conv, new_shape)
        for k, pooling in enumerate([K.max, K.min, K.mean]):
            print output[i,j,k,:]
            output[i,j,k,:] = pooling(conv, 0)

---> 15 output[i,j,k,:] = pooling(conv, 0)

TypeError: 'Tensor' object does not support item assignment

In the code I implemented above, each pooling(conv, 0) return us a Tensor("Squeeze_2:0", shape=(8,), dtype=float32) , how am I suppose to pack these tensors into a larger one with shape I defined in output?

Upvotes: 0

Views: 6056

Answers (1)

xxx222
xxx222

Reputation: 3244

output = []
for i, atten_embed in enumerate(atten_embeds):
    for j, ws in enumerate(wss):
        conv_layer = conv_layers_A[j]
        conv = conv_layer(atten_embed)
        new_shape = (reduce(lambda x,y:x*y, conv.get_shape()[:-1]).value,num_filters)
        conv = K.reshape(conv, new_shape)
        for k, pooling in enumerate([K.max, K.min, K.mean]):
            output.append(pooling(conv, 0))

output = tf.reshape(tf.pack(output), shape=(2, len(wss), 3, num_filters))

Upvotes: 1

Related Questions