尝试创建卷积自动编码器时遇到此问题。
________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_56 (InputLayer) (None, 8192, 4) 0
_________________________________________________________________
conv1d_147 (Conv1D) (None, 8192, 64) 8256
_________________________________________________________________
leaky_re_lu_138 (LeakyReLU) (None, 8192, 64) 0
_________________________________________________________________
max_pooling1d_82 (MaxPooling (None, 256, 64) 0
_________________________________________________________________
conv1d_148 (Conv1D) (None, 256, 32) 32800
_________________________________________________________________
leaky_re_lu_139 (LeakyReLU) (None, 256, 32) 0
_________________________________________________________________
max_pooling1d_83 (MaxPooling (None, 16, 32) 0
_________________________________________________________________
conv1d_149 (Conv1D) (None, 16, 32) 16416
_________________________________________________________________
leaky_re_lu_140 (LeakyReLU) (None, 16, 32) 0
_________________________________________________________________
up_sampling1d_48 (UpSampling (None, 256, 32) 0
_________________________________________________________________
conv1d_150 (Conv1D) (None, 256, 64) 65600
_________________________________________________________________
leaky_re_lu_141 (LeakyReLU) (None, 256, 64) 0
_________________________________________________________________
up_sampling1d_49 (UpSampling (None, 8192, 64) 0
=================================================================
Total params: 123,072
Trainable params: 123,072
Non-trainable params: 0
_________________________________________________________________
我需要将up_sampling1d_49 [(None, 8192, 64)]
转换为与input_56 [(None, 8192, 4)]
相同的形状,以训练自动编码器。有什么办法吗?
我尝试将Flatten层与MLP层一起使用。
import keras as K
import scipy as sp
##Creating the model
fil,col=8192,4
entrada = K.layers.Input(shape=(fil,col) )
c1 = K.layers.Conv1D(filters=64,kernel_size= 32, padding='same')(entrada)
lr1 = K.layers.LeakyReLU(alpha=0.35)(c1)
p1 = K.layers.MaxPool1D(pool_size=32)(lr1)
c2 = K.layers.Conv1D(filters=32,kernel_size=16, padding='same')(p1)
lr2 = K.layers.LeakyReLU(alpha=0.25)(c2)
p2 = K.layers.MaxPool1D(pool_size=16)(lr2)
c3 = K.layers.Conv1D(filters=32,kernel_size=16, padding='same')(p2)
lr3 = K.layers.LeakyReLU(alpha=0.25)(c3)
p3 = K.layers.UpSampling1D(size=16)(lr3)
c4 = K.layers.Conv1D(filters=64,kernel_size=32, padding='same')(p3)
lr3 = K.layers.LeakyReLU(alpha=0.35)(c4)
p4 = K.layers.UpSampling1D(size=32)(lr3)
model = K.models.Model(entrada,p4)
答案 0 :(得分:0)
UpSampling1D层的输入的形状为(batch, steps, features)
,输出的形状为(batch, upsampled_steps, features)
。因此,UpSampling1D层不会更改通道尺寸。因此,您的选择是转换conv1d_150
的过滤器数。
c4 = K.layers.Conv1D(filters=64,kernel_size=32, padding='same')(p3)
lr3 = K.layers.LeakyReLU(alpha=0.35)(c4)
p4 = K.layers.UpSampling1D(size=32)(lr3)
这会将conv1d_150
和leaky_re_lu_141
的输出形状更改为(None, 256, 4)
,将up_sampling1d_49
的输出形状更改为(None, 8192, 4)
。