我对keras相当陌生。我现在正尝试在keras中包含conv3d_transpose层。我想使用它来进行图像分割。我的代码如下:
def vnet_model_new():
model = Sequential()
#build the first three convolutional layers
model.add(Conv3D(16, 5, input_shape=(56,56,56,1),padding = 'same', kernel_initializer = 'he_normal'))
model.add(PReLU(shared_axes=[1,2],name='prelu1'))
#first down sampling
model.add(Conv3D(32, 5, strides=(2,2,2), padding = 'same', kernel_initializer = 'he_normal'))
model.add(PReLU(shared_axes=[1,2],name='prelu2'))
model.add(Conv3D(32, 5, padding = 'same', kernel_initializer = 'he_normal'))
model.add(PReLU(shared_axes=[1,2],name='prelu3'))
model.add(Conv3D(32, 5, padding = 'same', kernel_initializer = 'he_normal'))
model.add(PReLU(shared_axes=[1,2],name='prelu4'))
model.add(Conv3D(32, 5, strides=(2,2,2), padding = 'same', kernel_initializer = 'he_normal'))
model.add(PReLU(shared_axes=[1,2],name='prelu5'))
model.add(Conv3D(64, 5, padding = 'same', kernel_initializer = 'he_normal'))
model.add(PReLU(shared_axes=[1,2],name='prelu6'))
model.add(Conv3D(64, 5, padding = 'same', kernel_initializer = 'he_normal'))
model.add(PReLU(shared_axes=[1,2],name='prelu7'))
model.add(InputLayer(input_tensor=tf.nn.conv3d_transpose(model.layers[7].output,5, output_shape=(28,28,28,1),strides=(2,2,2)))[0])
model.add(Conv3D(32, 5, padding = 'same', kernel_initializer = 'he_normal'))
model.add(PReLU(shared_axes=[1,2],name='prelu8'))
model.add(Conv3D(32, 5, padding = 'same', kernel_initializer = 'he_normal'))
model.add(PReLU(shared_axes=[1,2],name='prelu9'))
model.add(UpSampling3D(size=(2, 2, 2), data_format=None))
return model
如果我现在这样做:
model = vnet_model_new()
我得到了错误:
IndexError Traceback (most recent call last)
<ipython-input-42-d5a1c0f1067b> in <module>()
33
34 #apply segmentation model
---> 35 model = vnet_model_new()
36 model.compile(optimizer='adam', loss=dice_coef_loss, metrics=[dice_coef])
37 model.fit(train_features, train_labels, validation_data=(test_features, test_labels), epochs=10, batch_size=50, verbose=2)
<ipython-input-42-d5a1c0f1067b> in vnet_model_new()
18 model.add(Conv3D(64, 5, padding = 'same', kernel_initializer = 'he_normal'))
19 model.add(PReLU(shared_axes=[1,2],name='prelu7'))
---> 20 model.add(InputLayer(input_tensor=tf.nn.conv3d_transpose(model.layers[7].output,5, output_shape=(28,28,28,1),strides=(2,2,2)))[0])
21 model.add(Conv3D(32, 5, padding = 'same', kernel_initializer = 'he_normal'))
22 model.add(PReLU(shared_axes=[1,2],name='prelu8'))
~\Anaconda2\lib\site-packages\tensorflow\python\ops\nn_ops.py in conv3d_transpose(value, filter, output_shape, strides, padding, data_format, name)
1450 filter = ops.convert_to_tensor(filter, name="filter")
1451 axis = 1 if data_format == "NCDHW" else 4
-> 1452 if not value.get_shape()[axis].is_compatible_with(filter.get_shape()[4]):
1453 raise ValueError("input channels does not match filter's input channels, "
1454 "{} != {}".format(value.get_shape()[axis],
~\Anaconda2\lib\site-packages\tensorflow\python\framework\tensor_shape.py in __getitem__(self, key)
522 return TensorShape(self._dims[key])
523 else:
--> 524 return self._dims[key]
525 else:
526 if isinstance(key, slice):
IndexError: list index out of range
我在做什么错? 提前致谢! 埃拉