Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

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

Writer Olivia Zamora

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?

1 Answer

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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.