自动编码器:从卷积到超分辨率的深入探索
1. 自动编码器基础
自动编码器旨在学习低维表示(潜在空间),然后根据预定义任务(如恒等函数)学习一种变换来重建图像。以下是使用MNIST数据集构建和训练自动编码器的示例代码:
layers = [ {'n_nodes': 256 }, { 'n_nodes': 128 }, { 'n_nodes': 64 } ]
inputs = Input((28, 28, 1))
encoding = encoder(inputs, layers)
outputs = decoder(encoding, layers, (28, 28, 1))
ae = Model(inputs, outputs)
from tensorflow.keras.datasets import mnist
import numpy as np
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train = (x_train / 255.0).astype(np.float32)
x_test = (x_test / 255.0).astype(np.float32)
x_train = np.expand_dims(x_train, axis=-1)
x_test = np.expand_dims(x_test, axis=-1)
ae.compile(loss='binary_crossentropy', optimizer='adam',
metrics=['accuracy'])
ae.fit(x_train, x_train, ep
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



