【问题标题】:visualize the output of convolutional layer in autoencoder在自动编码器中可视化卷积层的输出
【发布时间】:2019-06-11 00:20:03
【问题描述】:

我有一个简单的自动编码器,我想查看每一层的输出,尤其是潜在空间。我知道在每一层之后实现了一些特征,如边缘,但我想显示每一层的输出。我想知道每一层的输出是什么,并且我想在我的自动编码器中可视化每一层的输出。我该怎么做,我该怎么做? 因为我对我的网络没有真正的想象,我想知道我的网络的每一层发生了什么。我真的需要它。请帮我解决这个问题。我在等你的消息。

from keras.layers import Input, Dense, Conv2D, MaxPooling2D, UpSampling2D
from keras.models import Model
from keras import backend as K
from keras.datasets import mnist
import numpy as np
input_img = Input(shape=(28, 28, 1))  # adapt this if using `channels_first` image data format

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)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
encoded = MaxPooling2D((2, 2), padding='same')(x)

# at this point the representation is (4, 4, 8) i.e. 128-dimensional

x = Conv2D(8, (3, 3), activation='relu', padding='same')(encoded)
x = UpSampling2D((2, 2))(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
x = UpSampling2D((2, 2))(x)
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')

#train part


(x_train, _), (x_test, _) = mnist.load_data()

x_train = x_train.astype('float32') / 255.
x_test = x_test.astype('float32') / 255.
x_train = np.reshape(x_train, (len(x_train), 28, 28, 1))  # adapt this if using `channels_first` image data format
x_test = np.reshape(x_test, (len(x_test), 28, 28, 1))  # adapt this if using `channels_first` image data format
from keras.callbacks import TensorBoard

autoencoder.fit(x_train, x_train,
                epochs=50,
                batch_size=128,
                shuffle=True,
                validation_data=(x_test, x_test),
                callbacks=[TensorBoard(log_dir='/tmp/autoencoder')])

【问题讨论】:

标签: tensorflow keras keras-layer


【解决方案1】:

使用Keras Tutorial 可视化输出。

你期望的第一层Haar-like Features(很多直线等等)。万事如意!

【讨论】:

  • 我想将中间层的输出显示为图像,我该怎么做?请给出示例代码或有示例代码的链接,因为我对keras不熟悉。
  • 是的,我读过它,但它使用了 VGG 我想拥有我的网络并在 mnist 上显示我的结果!?
  • 嗨,没有人可以帮助我吗?我还看到了这个链接keras.io/getting-started/faq/…,它是关于显示中间层的。但我不明白什么是 x,我应该用什么代替它?请解释一下我现在该怎么办?我知道这很简单,但我是初学者;(
  • X 是你唯一的。你看过我发的链接吗?概念相同,但深入讨论
  • 如果您更改了代码,您应该更新您的问题以反映这一点。如果更改非常大,您应该提出一个新的、更具体的问题
猜你喜欢
  • 1970-01-01
  • 2016-05-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-18
  • 2019-11-09
  • 2019-05-17
  • 2017-01-04
相关资源
最近更新 更多