0
我遇到以下代碼段obs_pattern
,obs_seq
和obs_seq_s
不會產生預期行爲的問題。我嘗試過使用TensorFlow 1.2.1。我懷疑有什麼不對。交互式會話eval和tf.random_uniform不會產生預期的輸出
import tensorflow as tf
sess = tf.InteractiveSession()
seq_length = 5
num_bits = 4
obs_pattern_shape = [num_bits, seq_length]
obs_pattern = tf.cast(
tf.random_uniform(obs_pattern_shape, minval=0, maxval=2, seed=1234, dtype=tf.int32),
tf.float32)
print(obs_pattern.eval())
seq_length_zeros = tf.zeros([1, seq_length])
obs_seq = tf.concat([obs_pattern, seq_length_zeros], axis=0)
print(obs_seq.eval())
add_vec = tf.one_hot([num_bits], (num_bits + 1), on_value = 1.0, off_value=0.0, axis=0)
obs_seq_s = tf.concat([obs_seq, add_vec], axis=1)
print(obs_seq_s.eval())
sess.close()
obs_pattern
[[ 1. 1. 1. 0. 0.]
[ 0. 0. 0. 1. 0.]
[ 0. 1. 1. 0. 0.]
[ 0. 1. 0. 0. 0.]]
obs_seq
[[ 1. 1. 0. 1. 1.]
[ 0. 1. 1. 0. 1.]
[ 1. 1. 1. 0. 0.]
[ 1. 1. 0. 1. 0.]
[ 0. 0. 0. 0. 0.]]
obs_seq_s
[[ 1. 0. 0. 0. 0. 0.]
[ 0. 0. 1. 0. 0. 0.]
[ 0. 1. 0. 0. 0. 0.]
[ 0. 1. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0. 1.]]
編輯:基於噸 他評論下面我改變obs_pattern和它的行爲,因爲我還以爲
import numpy as np
arr = np.random.randint(2, size=(num_bits, seq_length))
obs_pattern = tf.convert_to_tensor(arr, dtype=tf.float32)
甜美!感謝那 – flyingmadden