张量流中的恢复模型为relu操作提供了不同的结果

时间:2018-04-06 03:54:08

标签: tensorflow random convolution non-deterministic

从恢复的模型中检索的权重不会更改,输入也是常量 但是'Relu:0'操作的输出每次都会给出不同的结果。

以下是我的代码:

sess=tf.Session()   
saver = tf.train.import_meta_graph('checkpoints/checkpoints_otherapproach_1/cameranetwork_RAID_CNN-3100.meta')
saver.restore(sess,tf.train.latest_checkpoint(checkpoint_dir='checkpoints/checkpoints_otherapproach_1/'))

images = tf.get_default_graph().get_tensor_by_name('images:0')
phase = tf.get_default_graph().get_tensor_by_name('phase:0')
Activ = tf.get_default_graph().get_tensor_by_name('network/siamese_model/convolution_1/conv_1/Relu:0')

image_array = np.zeros(shape = [1,3,128,64,3]) #*******
imagepath = 'RAiD_Dataset' + '/images_afterremoving_persons_notinallcameras/'+'test'+'/camera_'+str(1)
fullfile_name = imagepath+"/"+ 'camera_1_person_23_index_1.jpg'
image_array[0][0] = cv2.imread(fullfile_name)
image_array[0][1] = image_array[0][0]
image_array[0][2] = image_array[0][0]
image_array = image_array.astype(np.float32)

feed_dict_values ={images: image_array, phase:False}
temp2 = sess.run(Activ, feed_dict =feed_dict_values)
temp1 = sess.run(Activ, feed_dict =feed_dict_values)

print (temp1==temp2).all()   #output is false

1 个答案:

答案 0 :(得分:3)

有两个可能的原因:

  1. 一些tensorflow操作继承了CUDA的非确定性行为。这导致小的数值误差(可能通过非线性放大)。有关如何在单个CPU线程上运行模型的信息,请参阅this answer。如果这两个数组在这种情况下会变得相同,那就是这种情况。

  2. 我假设您知道要加载的图形,但由于操作故意引入随机数据或不定数据,图形本身可能会“按设计”产生不一致的结果。例如,考虑使用随机数生成器的操作或每次评估Activ时更新变量的操作(例如,tf.assign)。