TypeError:'Tensor'对象不支持项目分配

时间:2017-01-17 21:32:44

标签: tensorflow keras

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输出[i,j,k,:] =汇集(转换,0)

     

TypeError:'Tensor'对象不支持项目分配

在我上面实现的代码中,每个pooling(conv, 0)都给我们一个Tensor("Squeeze_2:0", shape=(8,), dtype=float32) ,我怎么想把这些张量打包成一个在output中定义的形状更大的张量?

1 个答案:

答案 0 :(得分:1)

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))