2017-06-29 2 views
1

ich den folgenden Code versuchtTensorflow - tf.matmul von konv Funktionen und ein Vektor als Batch matmul

batch_size= 128 
c1 = tf.zeros([128,32,32,16]) 
c2 = tf.zeros([128,32,32,16]) 
c3 = tf.zeros([128,32,32,16]) 

c = tf.stack([c1, c2, c3], 4) (size: [128, 32, 32, 16, 3]) 

alpha = tf.zeros([128,3,1]) 

M = tf.matmul(c,alpha) 

Und es macht Fehler bei tf.matmul.

Was ich will, ist nur eine lineare Kombination alpha[0]*c1 + alpha[1]*c2 + alpha[2]*c3 bei jeder Probe. Wenn die Stapelgröße 1 ist, ist dieser Code in Ordnung, aber wenn nicht, wie kann ich es tun?

Sollte ich c1,c2,c3 umformen?

Antwort

0

Ich denke, dieser Code funktioniert; verifizierte es.

import tensorflow as tf 
import numpy as np 

batch_size= 128 
c1 = tf.ones([128,32,32,16]) 
c2 = tf.ones([128,32,32,16]) 
c3 = tf.ones([128,32,32,16]) 

c = tf.stack([c1, c2, c3], 4) 

alpha = tf.zeros([1,3]) 

for j in range(127): 
    z = alpha[j] + 1 
    z = tf.expand_dims(z,0) 
    alpha = tf.concat([alpha,z],0) 


M = tf.einsum('aijkl,al->aijk',c,alpha) 



print('') 

with tf.Session() as sess: 
    _alpha = sess.run(alpha) 
    _M = sess.run(M) 


print('') 
Verwandte Themen