2017-06-17 14 views
2

シンプルなオートエンコーダーを実行しようとしていますが、すべてのトレーニング入力は同じです。トレーニングデータの特徴は3であり、隠れた層は3つのノードを有する。私はその入力でオートエンコーダーを訓練してから、再びエンコード/デコードを試みます(オートエンコーダーが何も変更せずにそのまま渡すと、うまくいきます)Keras autoencoderシンプルな例が異常な出力を持っています

とにかく、私は午前理由を理解するためにちょっとしたことをしています。私のコードで何かが間違っているかどうか、あるいは自動実装の実装を理解しているかどうかはわかりません。これは参考のためのコードです。

P.S.私はエポッシュの数、トレーニングセットの例数、バッチサイズ、トレーニングデータの値を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)` 

どれでも役立つだろう私は間違ったことを理解している可能性が高いので、この質問はそれほど難しい答えではありません。

答えて

1

エラーはdecoded = Dense(3, activation='sigmoid')(encoded)です。

それは例えば、 linearsigmoidを交換するか、それを削除し、あなたがより多くのエポックを追加することができます(1、0)の範囲で出力を制限するので、あなたは、 sigmoidアクティベーションを使用しないでください

列車は1000エポック。この設定では、私はあなたがそれがPythonの:-)でkeywordあるよう

[[ 0.98220336 1.98066235 2.98398876] 
[ 0.98220336 1.98066235 2.98398876] 
[ 0.98220336 1.98066235 2.98398876] 
[ 0.98220336 1.98066235 2.98398876] 
[ 0.98220336 1.98066235 2.98398876] 
[ 0.98220336 1.98066235 2.98398876] 
[ 0.98220336 1.98066235 2.98398876] 
[ 0.98220336 1.98066235 2.98398876] 
[ 0.98220336 1.98066235 2.98398876]] 

はまた、あなたが、別の名前で入力inを交換する必要があります必要なものを取得します。

1

次@dancheの提案を適用した後は、更新されたコードとの結果ですが、私はepocs = 10000

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]]) 
input = Input(shape=(3,)) 
encoded = Dense(encoding_dim, activation='relu')(input) 
decoded = Dense(3, activation='linear')(encoded) 

# this model maps an input to its reconstruction 
autoencoder = Model(input, decoded) 
autoencoder.compile(optimizer='adadelta', loss='mse') 

autoencoder.fit(x_train, x_train,epochs=10000,batch_size=4) 
print(autoencoder.predict(x_train)) 



Epoch 10000/10000 
8/8 [==============================] - 0s - loss: 2.4463e-04  
[[ 0.99124289 1.98534203 2.97887278] 
[ 0.99124289 1.98534203 2.97887278] 
[ 0.99124289 1.98534203 2.97887278] 
[ 0.99124289 1.98534203 2.97887278] 
[ 0.99124289 1.98534203 2.97887278] 
[ 0.99124289 1.98534203 2.97887278] 
[ 0.99124289 1.98534203 2.97887278] 
[ 0.99124289 1.98534203 2.97887278]] 
を増加させた後の結果を得ました
関連する問題