1.普通自编码器
2.多层自编码器
3.卷积自编码器
4.稀疏自编码器
sigmoid
或者relu
from keras.layers import Dense, Input, Activation
input_size = 256
hidden_size = 32
output_size = 256
x = Input(shape=(input_size,))
# Encoder
h = Dense(hidden_size, activation='sigmoid')(x)
# Decoder
r = Dense(output_size, activation='sigmoid')(h)
autoencoder = Model(input=x, output=r)
autoencoder.compile(optimizer='adam', loss='mse')
autoencoder.fit(input_data, input_data, batch_size=128, epochs=10000, verbose=2)
from keras.layers import Dense, Input, Activation
input_size = 256
hidden_size = 32
output_size = 256
x = Input(shape=(input_size,))
# Encoder
hidden_1 = Dense(hidden_size, activation='sigmoid')(x)
h = Dense(code_size, activation='sigmoid')(hidden_1)
# Decoder
hidden_2 = Dense(hidden_size, activation='relu')(h)
r = Dense(input_size, activation='sigmoid')(hidden_2)
autoencoder = Model(input=x, output=r)
autoencoder.compile(optimizer='adam', loss='mse')
autoencoder.fit(input_data, input_data, batch_size=128, epochs=10000, verbose=2)
x = Input(shape=(28, 28,1))
# Encoder
conv1_1 = Conv2D(16, (3, 3), activation='relu', padding='same')(x)
pool1 = MaxPooling2D((2, 2), padding='same')(conv1_1)
conv1_2 = Conv2D(8, (3, 3), activation='relu', padding='same')(pool1)
pool2 = MaxPooling2D((2, 2), padding='same')(conv1_2)
conv1_3 = Conv2D(8, (3, 3), activation='relu', padding='same')(pool2)
h = MaxPooling2D((2, 2), padding='same')(conv1_3)
# Decoder
conv2_1 = Conv2D(8, (3, 3), activation='relu', padding='same')(h)
up1 = UpSampling2D((2, 2))(conv2_1)
conv2_2 = Conv2D(8, (3, 3), activation='relu', padding='same')(up1)
up2 = UpSampling2D((2, 2))(conv2_2)
conv2_3 = Conv2D(16, (3, 3), activation='relu')(up2)
up3 = UpSampling2D((2, 2))(conv2_3)
r = Conv2D(1, (3, 3), activation='sigmoid', padding='same')(up3)
autoencoder = Model(input=x, output=r)
autoencoder.compile(optimizer='adam', loss='mse')
from keras.layers import Dense, Input, Activation
input_size = 256
hidden_size = 32
output_size = 256
x = Input(shape=(input_size,))
# Encoder
h = Dense(hidden_size, activation='sigmoid', activity_regularizer=regularizers.l1(10e-6))(x)
# Decoder
r = Dense(output_size, activation='sigmoid')(h)
autoencoder = Model(input=x, output=r)
autoencoder.compile(optimizer='adam', loss='mse')
autoencoder.fit(input_data, input_data, batch_size=128, epochs=10000, verbose=2)