Why was the result different when I resized the test batch in tensorflow

Here is my train code:

x = tf.placeholder(tf.float32, [None, 2, 3])
cell = tf.nn.rnn_cell.GRUCell(10)

_, state = tf.nn.dynamic_rnn(
        cell = cell,
        inputs = x,
        dtype = tf.float32)
# train
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    x_ = np.ones([2,2,3],np.float32)
    output = sess.run(state, feed_dict= {x: x_})
    print output    
    saver = tf.train.Saver()
    saver.save(sess,'./model')

      

Result:

[[ 0.12851571 -0.23994535  0.23123585 -0.00047993 -0.02450397
  -0.21048039 -0.18786618  0.04458345 -0.08603278 -0.08259721]
 [ 0.12851571 -0.23994535  0.23123585 -0.00047993 -0.02450397
  -0.21048039 -0.18786618  0.04458345 -0.08603278 -0.08259721]]

      

Here is my test code:

x = tf.placeholder(tf.float32, [None, 2, 3])
cell = tf.nn.rnn_cell.GRUCell(10)

_, state = tf.nn.dynamic_rnn(
        cell = cell,
        inputs = x,
        dtype = tf.float32)
with tf.Session() as sess:
    x_ = np.ones([1,2,3],np.float32)
    saver = tf.train.Saver()
    saver.restore(sess,'./model')
    output = sess.run(state, feed_dict= {x: x_})
    print output

      

Then I get:

[[ 0.12851571 -0.23994535  0.2312358  -0.00047993 -0.02450397 
  -0.21048039 -0.18786621  0.04458345 -0.08603278 -0.08259721]]

      

As you can see, the result has changed slightly. When I set the test batch to 2, the result is the same as the train result. So what is it? My tf version is 0.12

+3
tensorflow


source to share


No one has answered this question yet

Check out similar questions:

2
Replacing tf.placeholder and feed_dict with tf.data API
2
Simple Feeder Neural Network with TensorFlow Won't Learn
1
Tensorflow: Plot chart with batch sizes varying in size 1?
1
some questions about run_epoch function in ptb_word_lm.py tensorflow rnn tuorial
0
Tensorflow: InvalidArgumentError when feeding numpy ndarray to placeholder
0
ValueError: Unable to pass shape (4,) value for Tensor 'Placeholder_36: 0' which has the shape '(?, 4)'
0
Tensorflow: ValueError While extracting parameters in LSTM
0
Error when calling global_variables_initializer in TensorFlow
0
Tflite output does not match tensorflow output for conv2d_transpose
0
Tensorflow Dataset iterator consumes large amounts of memory



All Articles
Loading...
X
Show
Funny
Dev
Pics