【发布时间】:2019-12-29 18:01:34
【问题描述】:
当我训练我的自动编码器时,无论我训练多少损失都不会改变。
#Importing training data
inp = open('train.csv',"rb")
X = pickle.load(inp)
X = X/255.0
X = np.array(X)
X = np.reshape(X,(-1,25425))
input_img =tf.keras.layers.Input(25425,)
encoded1 = tf.keras.layers.Dense(75,activation=tf.nn.relu)(input_img)
encoded2 = tf.keras.layers.Dense(50,activation=tf.nn.relu)(encoded1)
decoded = tf.keras.layers.Dense(25425, activation='sigmoid')(encoded2)
# The input of the autoencoder is the image (input_img), and the output is the decoder layer (decoded)
autoencoder = tf.keras.Model(input_img, decoded)
encoder = tf.keras.Model(input_img, encoded2)
encoded_input = tf.keras.layers.Input(shape=(50,))
# The decoded only consists of the last layer
decoder_layer = autoencoder.layers[-1](encoded_input)
# The input to the decoder is the vector of the encoder which will be fed (using encoded_input), the output is the last layer of the network (decoder_layer)
decoder = tf.keras.Model(encoded_input, decoder_layer)
autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')
autoencoder.fit(X, X, epochs=50, shuffle=True)
# Save the weights
autoencoder.save_weights('model_weights.h5')
# Save the model architecture
with open('model_architecture.json', 'w') as f:
f.write(autoencoder.to_json())
我希望我可以让训练更好地发挥作用但是我的损失停留在 0.6932
【问题讨论】:
-
输出维度从 50 大幅增加到 25425。另外,不要将 ReLU 与 sigmoid 一起使用。
标签: python tensorflow keras autoencoder