当我使用步长大于过滤器大小的tf.nn.conv2d时,conv2d的输出在不同的Session.run()之间是不同的。 我可以让tf.nn.conv2d产生确定性输出吗?
我使用master分支上的tensorflow测试以下代码,cuda 7.5和cudnn v5。
import tensorflow as tf
import numpy as np
input_batch_size = 1
input_height = 80
input_width = 80
input_num_channels = 100
filter_height = 1
filter_width = 1
output_num_channels= 30
stride = 2
nn_input = tf.placeholder(shape=[input_batch_size, input_height, input_width,
input_num_channels],
dtype=tf.float32)
f = tf.get_variable('f', shape=[filter_height, filter_width, input_num_channels,
output_num_channels],
initializer=tf.random_uniform_initializer())
conv = tf.nn.conv2d(nn_input, f, strides=[1, stride, stride, 1],
padding='SAME', use_cudnn_on_gpu=True)
sess = tf.InteractiveSession()
sess.run(tf.initialize_all_variables())
i = np.random.random([input_batch_size, input_height,
input_width, input_num_channels])
for _ in range(10000):
diff = np.abs(sess.run(conv, feed_dict={nn_input: i}) -
sess.run(conv, feed_dict={nn_input: i})).max()
if diff:
print(diff) # print 30.9991
break