2016-04-26 78 views
4

我有以下批处理形状:TensorFlow:如何通过权重变量批量变更批量张量?

[?,227,227] 

而下面的权重变量:

weight_tensor = tf.truncated_normal([227,227],**{'stddev':0.1,'mean':0.0}) 

weight_var = tf.Variable(weight_tensor) 

但是当我做tf.batch_matmul

matrix = tf.batch_matmul(prev_net_2d,weight_var) 

我失败,出现以下错误:

ValueError: Shapes (?,) and() must have the same rank


所以我的问题变成:我该怎么做?

如何在2D中获得weight_variable乘以每个单独图片(227x227)以便产生(227x227)输出?这个操作的平板版本完全耗尽的资源...加上渐变不会在平坦的形式正确地改变权重...


或者:我怎么拆沿批维输入张量(?,),以便我可以使用我的weight_variable在每个分裂张量上运行tf.matmul函数?

+0

曾找到解决这个? – MattClimbs

+0

我需要解决方案以及..分享? – Shivam

+0

@ User104我可能已经想通了。这个周末我打算拉起我的旧代码......但我现在还没有模糊不清。 – bordeo

回答

4

你可以沿着第一维度瓦的重量

weight_tensor = tf.truncated_normal([227,227],**{'stddev':0.1,'mean':0.0}) 
weight_var = tf.Variable(weight_tensor) 
weight_var_batch = tf.tile(tf.expand_dims(weight_var, axis=0), [batch_size, 1, 1]) 
matrix = tf.matmul(prev_net_2d,weight_var_batch) 

虽然batch_matmul不存在了

+0

这将是很好的解释对tf.expand_dims和tf.tile的调用。无论如何感谢您的答案,+1 :) – dburner