Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the output of tf.nn.bias_add(value, bias) ever have a different shape than shape of value

Tags:

tensorflow

So in the convolutional neural network cifar10 example in tensorflow, in the inference() method of cifar10.py I see several instances of this:

bias = tf.reshape(tf.nn.bias_add(conv, biases),conv.get_shape().as_list())

It seems like the reshape is making sure the output of bias_add(value, bias) has the shape of value

My question is, is the tf.reshape() necessary? Is there a situation where tf.nn.bias_add(value, bias) will not return a tensor with the same shape as value?

like image 725
Petrarch Avatar asked Nov 16 '15 02:11

Petrarch


1 Answers

The shape of the result of tf.nn.bias_add(value, bias) is always the same as the shape of value, so these calls to tf.reshape() are unnecessary.

Occasionally, calls to tf.reshape() are used to add explicit information about the shape, but the recommended way to do this, per the FAQ, is to use the Tensor.set_shape() method to add shape information without adding a redundant operation to the graph.

like image 196
mrry Avatar answered Nov 09 '22 21:11

mrry