2017-01-17 5 views
0
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‘ Objekt nicht unterstützt Artikel Zuordnung

TypeError: 'Tensor' object does not support item assignment

Im Code, den ich oben ausgeführt, die jeweils pooling(conv, 0) uns zurückgeben Tensor("Squeeze_2:0", shape=(8,), dtype=float32) , wie bin ich nehme an, diese Tensoren in eine größere mit Form zu packen I definiert in output?

Antwort

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