我正在尝试运行一个简单的自动编码器,所有的训练输入都是一样的.训练数据特征等于3,隐藏层中有3个节点.我用该输入训练自动编码器,然后我再次尝试预测它(编码/解码)(所以如果自动编码器按原样传递一切而没有任何改变它应该工作)
无论如何,情况并非如此,我有点难以理解为什么.我不确定我的代码或者我对autoencdoer实现的理解是否有问题.这是代码供参考.
PS我玩了多个epoches,训练集中的例子数量,批量大小,使训练数据值在0-1之间,并且跟踪损失值,但这也没有帮助.
`
from keras.layers import Input, Dense
from keras.models import Model
import numpy as np
# this is the size of our encoded representations
encoding_dim = 3
x_train=np.array([[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3]])
in= Input(shape=(3,))
encoded = Dense(encoding_dim, activation='relu')(in)
decoded = Dense(3, activation='sigmoid')(encoded)
# this model maps an input to its reconstruction
autoencoder = Model(in, decoded)
autoencoder.compile(optimizer='adadelta', loss='mse')
autoencoder.fit(x_train, x_train,
epochs=100,
batch_size=4)
autoencoder.predict(x_train)
Run Code Online (Sandbox Code Playgroud)
`
我得到的输出应该与输入相同(或至少接近),但我得到了这个)
`Out[180]:
array([[ 0.80265796, 0.89038897, 0.9100889 ],
[ 0.80265796, 0.89038897, 0.9100889 ],
[ 0.80265796, 0.89038897, 0.9100889 ],
...,
[ …Run Code Online (Sandbox Code Playgroud)