用于分类目的的CNN自动编码器



我想使用 AE 的压缩层来训练简单的分类器或回归器。 实际上压缩层的形状是(64,128(,那么如何将该层转换为分类目的呢?如果我使用展平化功能,我的新层有 8192 维(我想这很大( 有人可以帮助我吗?

这里的代码:

input_img = Input(shape=(x_train1.shape[1], x_train1.shape[2])) # 0
conv1 = Convolution1D(16, 7, activation='relu', border_mode='same', init='glorot_normal', 
W_regularizer=regularizers.l2(0.0005))(input_img)  # 1
pool1 = MaxPooling1D(2, border_mode='same')(conv1)  # 2
conv2 = Convolution1D(32, 5, activation='relu', border_mode='same', init='glorot_normal', 
W_regularizer=regularizers.l2(0.0005))(pool1)  # 3
pool2 = MaxPooling1D(2, border_mode='same')(conv2)  # 4
conv3 = Convolution1D(64, 3, activation='relu', border_mode='same', 
init='glorot_normal',W_regularizer=regularizers.l2(0.0005))(pool2)  # 5
pool3 = MaxPooling1D(2, border_mode='same')(conv3)  # 6
conv4 = Convolution1D(128, 3, activation='relu', border_mode='same', init='glorot_normal', 
W_regularizer=regularizers.l2(0.0005))(pool3)  # 7
pool4 = MaxPooling1D(2, border_mode='same')(conv4)  # 8
stack_encoded = pool4
unpool4 = UpSampling1D(2)(pool4)  # 9
deconv3 = Convolution1D(64, 3, activation='relu', border_mode='same', 
init='glorot_normal',W_regularizer=regularizers.l2(0.0005))(unpool4)  # 10
unpool3 = UpSampling1D(2)(deconv3)  # 11
deconv2 = Convolution1D(32, 3, activation='relu', border_mode='same', 
init='glorot_normal',W_regularizer=regularizers.l2(0.0005))(unpool3)  # 12
unpool2 = UpSampling1D(2)(deconv2)  # 13
deconv1 = Convolution1D(16, 5, activation='relu', border_mode='same', 
init='glorot_normal',W_regularizer=regularizers.l2(0.0005))(unpool2)  # 14
unpool1 = UpSampling1D(2)(deconv1)  # 15
decoded = Convolution1D(1, 7, border_mode='same', 
init='glorot_normal',W_regularizer=regularizers.l2(0.0005))(unpool1)  # 16

这里是plot_model

谢谢

尼古拉斯

Flattened后,您可以添加一些Dense图层,最后添加一个包含类数的图层,以便在激活softmax进行分类。它几乎就像一个普通的CNN分类模型。

model.add(Flatten())
model.add(Dense(8192, activation='relu'))
model.add(Dense(2048, activation='relu'))
model.add(Dense(512, activation='relu'))
model.add(Dense(128, activation='relu'))
model.add(Dense(2, activation = 'softmax'))

相关内容

  • 没有找到相关文章

最新更新