在 Keras 中打印/保存自动编码器生成的要素



我有这个自动编码器:

input_dim = Input(shape=(10,))
encoded1 = Dense(30, activation = 'relu')(input_dim)
encoded2 = Dense(20, activation = 'relu')(encoded1)
encoded3 = Dense(10, activation = 'relu')(encoded2)
encoded4 = Dense(6, activation = 'relu')(encoded3)
decoded1 = Dense(10, activation = 'relu')(encoded4)
decoded2 = Dense(20, activation = 'relu')(decoded1)
decoded3 = Dense(30, activation = 'relu')(decoded2)
decoded4 = Dense(ncol, activation = 'sigmoid')(decoded3)
autoencoder = Model(input = input_dim, output = decoded4) 
autoencoder.compile(-...)
autoencoder.fit(...)

现在我想打印或保存以 encoded4 生成的功能。 基本上,从一个巨大的数据集开始,我想在训练部分之后提取自动编码器生成的特征,以获得我的数据集的受限表示。

你能帮我吗?

您可以通过创建"编码器"模型来实现:

encoder = Model(input = input_dim, output = encoded4)

这将使用您使用自动编码器训练的相同层实例,如果您在"推理模式"下使用它,则应生成该功能

,例如encoder.predict()

我希望这对:)有所帮助

所以,基本上,通过创建一个这样的编码器:

encoder = Model (input_dim,encoded4)
encoded_input=Input(shape=(6,))

然后使用:

encoded_data=encoder.predict(data)

其中predict函数中的数据是数据集,输出由

print encoded_data

是我的数据集的受限表示形式。

对吗?

谢谢

最新更新