Tensorflow 非零输入阵列的编码器输出零阵列
谁能告诉我这样行吗。我不知道为什么输入的非零数组在编码后会给出零输出。我是新手,我想知道我的代码是否有问题,如果这是正常的,为什么会这样?下面是我的代码。输入中的第五个数组是[0.1.0.1],相应的输出都是零Tensorflow 非零输入阵列的编码器输出零阵列,tensorflow,machine-learning,deep-learning,autoencoder,encoder-decoder,Tensorflow,Machine Learning,Deep Learning,Autoencoder,Encoder Decoder,谁能告诉我这样行吗。我不知道为什么输入的非零数组在编码后会给出零输出。我是新手,我想知道我的代码是否有问题,如果这是正常的,为什么会这样?下面是我的代码。输入中的第五个数组是[0.1.0.1],相应的输出都是零 k = 4 n = 4 M = 2**k sess = tf.Session() s = tf.random.uniform(shape=[10],minval=0,maxval=M,dtype=tf.int32) s_bin = tf.mod(tf.bitwise.right
k = 4
n = 4
M = 2**k
sess = tf.Session()
s = tf.random.uniform(shape=[10],minval=0,maxval=M,dtype=tf.int32)
s_bin = tf.mod(tf.bitwise.right_shift(tf.expand_dims(s,1), tf.range(4)), 2)
s_in = tf.cast(s_bin, float32)
print(sess.run(s_in))
[[0. 0. 1. 1.]
[0. 0. 0. 1.]
[1. 1. 1. 0.]
[1. 0. 1. 0.]
[0. 1. 0. 1.]
[1. 0. 1. 0.]
[1. 0. 1. 1.]
[1. 1. 1. 0.]
[0. 0. 0. 1.]
[0. 0. 0. 1.]]
tx = tf.keras.layers.Dense(units=k,activation="relu")(s_in)
tx = tf.keras.layers.Dense(units=n,activation=None)(tx)
x = tx / tf.sqrt(tf.reduce_mean(tf.square(tx)))
sess.run(tf.global_variables_initializer())
print(sess.run(x))
[[-2.493007 -0.43875682 -1.2676991 0.22669221]
[-1.639013 -1.3663911 -0.3158701 0.88604444]
[-0.8698901 -0.81329507 -0.12264011 0.5310494 ]
[-0.8162617 1.59715 -0.7286497 -1.11472 ]
[ 0. 0. 0. 0. ]
[-1.4972812 -1.1082815 -0.18187419 0.5983099 ]
[-0.8705666 1.0200655 -0.8402947 -0.68893915]
[-1.5335019 -0.3280608 -0.7810408 0.17321311]
[-1.8441036 1.0278493 -1.3127409 -0.7005408 ]
[-1.5730021 0.05295771 -0.8357831 -0.05726543]]