tensorflow - 获取特定层的输出作为测试数据的结果,而不是 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)
推荐阅读
- ubuntu - 添加 cron 作业?
- javascript - 类扩展了 Uint8Array,如何返回 Uint8Array?
- r - 使用不匹配的对删除括号之间的文本
- redis - redis中的订阅系统
- c# - 如何检查项目是否未初始化?
- javascript - 使用 JavaScript 从 JSON 获取信息并保存在 SQL Server 中
- java - Yelp android 工作室 VALIDATION_ERROR
- r - 在 for 循环中使用条件来创建唯一的面板 ID
- sas - 将宏函数作为参数传递给另一个宏函数
- rabbitmq - Spring Cloud Task 未使用 RabbitMQ 使用 Spring Cloud Stream 启动