我想運行一個簡單的自動編碼器,所有的訓練輸入是相同的。訓練數據特徵等於3,隱藏層有3個節點。我使用那個輸入來訓練自動編碼器,然後我試着再次預測它(編碼/解碼)(所以如果自動編碼器按原樣傳遞所有東西而不做任何改變,它應該可以工作)Keras autoencoder簡單的例子有一個奇怪的輸出
無論如何,情況並非如此,爲了理解原因,有點勉強。我不確定在我的代碼中,或者我對autoencdoer實現的理解中是否有問題。這裏是供參考的代碼。
P.S.我使用了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)
`
我得到的輸出應該是一樣的輸入(或至少接近),但我得到這個代替)
`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)`
任何幫助不勝感激,最有可能的是我明白了一些錯誤,所以希望這個問題不難回答。