获取特定层的输出作为测试数据的结果,以代替keras中的最后一层(自动编码器的潜在功能)

德什瓦尔

我正在尝试获取的输出latent layer/hidden layer以将其用作其他输入。我以一种有效的方式来训练模型,以最大程度地减少损失,因此我的模型可以有效地学习潜在特征,并尽可能地接近图像。我的模特是

input_img = Input(shape=(28, 28, 1))  # adapt this if using `channels_first` image data format

#Encoder
x = Conv2D(16, (3, 3), activation='relu', padding='same')(input_img)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)

encoded = MaxPooling2D((2, 2), padding='same')(x) 


# Decoder
x = Conv2D(8, (3, 3), activation='relu', padding='same')(encoded) 
x = UpSampling2D((2, 2))(x) # opposite of Pooling
x = Conv2D(16, (3, 3), activation='relu')(x)
x = UpSampling2D((2, 2))(x)
decoded = Conv2D(1, (3, 3), activation='sigmoid', padding='same')(x)

autoencoder = Model(input_img, decoded)
autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')

我希望将encoded图层的输出作为模型的输出。可能吗?广告如果是,请告诉我如何。

马克·塞里亚尼

你可以这样简单地做

autoencoder.fit(...)

latent_model = Model(input_img, encoded)
latent_representation = latent_model.predict(X)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档