【发布时间】:2017-11-19 22:43:00
【问题描述】:
我正在尝试运行一个简单的自动编码器,所有的训练输入都是相同的。训练数据特征等于3,隐藏层有3个节点。我用该输入训练自动编码器,然后我尝试再次预测它(编码/解码)(因此,如果自动编码器按原样传递所有内容而没有任何更改,它应该可以工作)
无论如何,情况并非如此,我有点难以理解为什么。我不确定我的代码是否有问题,或者我对 autoencdoer 实现的理解是否有问题。这是代码供参考。
附:我调整了 epoch 的数量、训练集中的示例数量、批量大小,使训练数据值介于 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)
`
我得到的输出应该与输入相同(或至少接近),但我得到的是这个)
`Out[180]:
array([[ 0.80265796, 0.89038897, 0.9100889 ],
[ 0.80265796, 0.89038897, 0.9100889 ],
[ 0.80265796, 0.89038897, 0.9100889 ],
...,
[ 0.80265796, 0.89038897, 0.9100889 ],
[ 0.80265796, 0.89038897, 0.9100889 ],
[ 0.80265796, 0.89038897, 0.9100889 ]], dtype=float32)`
任何帮助将不胜感激,很可能我理解错了,所以希望这个问题不是那么难回答。
【问题讨论】:
标签: python deep-learning keras autoencoder