如何在3d unet中添加Conv3DTransposer之前的重塑层?



ValueError:Concatenate层要求输入具有匹配的形状,除了连接轴。收到:input_shape=[(None, 44,44,32,128), (None, 28,28,16,512)]

x = Input((128, 128,36,1)) 
inputs = x 
f = 64 # number of filters
layers = [] # Create a list to store the outputs from each box
x = Conv3D(f, 3, activation = 'relu', padding = 'same') (x)
x = Conv3D(f, 3, activation = 'relu', padding = 'same') (x)
layers.append(x) # append the output from each box to layers
x = MaxPooling3D() (x)
f = f * 2
x = Conv3D(f, 3, activation = 'relu', padding = 'same') (x)
x = Conv3D(f, 3, activation = 'relu', padding = 'same') (x)
layers.append(x) # append the output from each box to layers
x = MaxPooling3D() (x)
f = f * 2
x = Conv3D(f, 3, activation = 'relu', padding = 'same') (x)
x = Conv3D(f, 3, activation = 'relu', padding = 'same') (x)
x = ZeroPadding3D(padding = (4,4,4))(x)     
layers.append(x) # append the output from each box to layers
x = MaxPooling3D() (x)
x = ZeroPadding3D(padding = (4,4,4))(x) 
f = f * 2
x = Conv3D(f, 3, activation = 'relu', padding = 'same') (x)
x = Conv3D(f, 3, activation = 'relu', padding = 'same') (x)
layers.append(x) # append the output from each box to layers
x = MaxPooling3D() (x)
x = ZeroPadding3D(padding = (4,4,4))(x) 
f = f * 2
ff2 = 128
#bottleneck
j = len(layers) - 1 # 6 - 1 = 5 in our case
x = Conv3D(f, 3, activation = 'relu', padding = 'same') (x)
x = Conv3D(f, 3, activation = 'relu', padding = 'same') (x)
x = Conv3DTranspose(ff2, 2, strides = (2, 2,2), padding = 'valid') (x)
x = Concatenate(axis = -1)([x, layers[j]])
j = j -1
#upsampling
ff2 = ff2//2
f = f // 2
x = Conv3D(f, 3, activation = 'relu', padding='same') (x)
x = Conv3D(f, 3, activation = 'relu', padding='same') (x)
x = Conv3DTranspose(ff2, 2, strides = (2, 2,2), padding = 'same') (x)
x = Concatenate(axis = -1)([x, layers[j]])
j = j - 1
outputs = Conv3D(1, 1, activation = 'sigmoid') (x)
#model creation
model = Model(inputs = [inputs], outputs = [outputs])
model.summary(line_length=150)

我能够重现这个问题。所以,我试着在重塑图层的同时添加一些图层。请在下面找到工作代码。

x = Input((128, 128,36,1)) 
inputs = x 
f = 64 # number of filters
layers = [] # Create a list to store the outputs from each box
x = Conv3D(f, 3, activation = 'relu', padding = 'same') (x)
x = Conv3D(f, 3, activation = 'relu', padding = 'same') (x)
layers.append(x) # append the output from each box to layers
x = MaxPooling3D() (x)
f = f * 2
x = Conv3D(f, 3, activation = 'relu', padding = 'same') (x)
x = Conv3D(f, 3, activation = 'relu', padding = 'same') (x)
layers.append(x) # append the output from each box to layers
x = MaxPooling3D() (x)
f = f * 2
x = Conv3D(f, 3, activation = 'relu', padding = 'same') (x)
x = Conv3D(f, 3, activation = 'relu', padding = 'same') (x)
x = ZeroPadding3D(padding = (4,4,4))(x)     
layers.append(x) # append the output from each box to layers
x = MaxPooling3D() (x)
x = ZeroPadding3D(padding = (4,4,4))(x) 
f = f * 2
x = Conv3D(f, 3, activation = 'relu', padding = 'same') (x)
x = Conv3D(f, 3, activation = 'relu', padding = 'same') (x)
layers.append(x) # append the output from each box to layers
x = MaxPooling3D() (x)
x = ZeroPadding3D(padding = (4,4,4))(x) 

f = f * 2
ff2 = 128
#bottleneck
j = len(layers) - 1 # 6 - 1 = 5 in our case
x = Conv3D(f, 3, activation = 'relu', padding = 'same') (x)
x = Conv3D(f, 3, activation = 'relu', padding = 'same') (x)
# Reshape layer 
x = Reshape((22, 22, 16, 1024))(x)
x = Conv3DTranspose(ff2, 1, strides = (1, 1, 1), padding = 'valid') (x) # Changed kernel size to 1 and strides to (1, 1, 1)
x = ZeroPadding3D(padding = (3,3,0))(x) 
x = Concatenate(axis = -1)([x, layers[j]])
ff2 = ff2//2
f = f // 2
x = Conv3D(f, 3, activation = 'relu', padding='same') (x)
x = Conv3D(f, 3, activation = 'relu', padding='same') (x)
x = Conv3DTranspose(ff2, 2, strides = (2, 2, 1), padding = 'same') (x) #Changed strides to (2, 2, 1)
# Added MaxPooling and ZeroPadding layers
x = MaxPooling3D(2,2) (x)
x = ZeroPadding3D(padding = (0,0,4))(x) 
x = Concatenate(axis = -1)([x, layers[j]])

相关内容

  • 没有找到相关文章

最新更新