Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在构建和训练3D Keras U-NET时获取值错误_Python_Tensorflow_Keras_Unity3d Unet - Fatal编程技术网

Python 在构建和训练3D Keras U-NET时获取值错误

Python 在构建和训练3D Keras U-NET时获取值错误,python,tensorflow,keras,unity3d-unet,Python,Tensorflow,Keras,Unity3d Unet,在使用keras为3D Unet构建的模型进行训练时,我得到了值错误:层conv3d_46的输入0与层不兼容:预期ndim=5,发现ndim=6。收到完整形状:[无,2,256,256,120,4]。我的数据的形状大小为(2、256、256、120、4)。 型号: data = Input(shape=inp_shape) flt=32 conv1 = Conv3D(flt, (3, 3, 3), activation='relu', padding='same')(data) conv1

在使用keras为3D Unet构建的模型进行训练时,我得到了值错误:层conv3d_46的输入0与层不兼容:预期ndim=5,发现ndim=6。收到完整形状:[无,2,256,256,120,4]。我的数据的形状大小为(2、256、256、120、4)。

型号:

data = Input(shape=inp_shape)
flt=32


conv1 = Conv3D(flt, (3, 3, 3), activation='relu', padding='same')(data)
conv1 = Conv3D(flt, (3, 3, 3), activation='relu', padding='same')(conv1)
pool1 = MaxPooling3D(pool_size=(2, 2, 2))(conv1)

conv2 = Conv3D(flt*2, (3, 3, 3), activation='relu', padding='same')(pool1)
conv2 = Conv3D(flt*2, (3, 3, 3), activation='relu', padding='same')(conv2)
pool2 = MaxPooling3D(pool_size=(2, 2, 2))(conv2)

conv3 = Conv3D(flt*4, (3, 3, 3), activation='relu', padding='same')(pool2)
conv3 = Conv3D(flt*4, (3, 3, 3), activation='relu', padding='same')(conv3)
pool3 = MaxPooling3D(pool_size=(2, 2, 2))(conv3)

conv4 = Conv3D(flt*8, (3, 3, 3), activation='relu', padding='same')(pool3)
conv4 = Conv3D(flt*8, (3, 3, 3), activation='relu', padding='same')(conv4)
pool4 = MaxPooling3D(pool_size=(2, 2, 2))(conv4)

conv5 = Conv3D(flt*16, (3, 3, 3), activation='relu', padding='same')(pool4)
conv5 = Conv3D(flt*8, (3, 3, 3), activation='relu', padding='same')(conv5)

up6 = concatenate([Conv3DTranspose(flt*8, (2, 2, 2), strides=(2, 2, 2), padding='same')(conv5), conv4], axis=-1)
conv6 = Conv3D(flt*8, (3, 3, 3), activation='relu', padding='same')(up6)
conv6 = Conv3D(flt*4, (3, 3, 3), activation='relu', padding='same')(conv6)

up7 = concatenate([Conv3DTranspose(flt*4, (2, 2, 2), strides=(2, 2, 2), padding='same')(conv6), conv3], axis=-1)
conv7 = Conv3D(flt*4, (3, 3, 3), activation='relu', padding='same')(up7)
conv7 = Conv3D(flt*2, (3, 3, 3), activation='relu', padding='same')(conv7)

up8 = concatenate([Conv3DTranspose(flt*2, (2, 2, 2), strides=(2, 2, 2), padding='same')(conv7), conv2], axis=4)
conv8 = Conv3D(flt*2, (3, 3, 3), activation='relu', padding='same')(up8)
conv8 = Conv3D(flt, (3, 3, 3), activation='relu', padding='same')(conv8)

up9 = concatenate([Conv3DTranspose(flt, (2, 2, 2), strides=(2, 2, 2), padding='same')(conv8), conv1], axis=4)
conv9 = Conv3D(flt, (3, 3, 3), activation='relu', padding='same')(up9)
conv9 = Conv3D(flt, (3, 3, 3), activation='relu', padding='same')(conv9)


conv10 = Conv3D(2, (1,1,1), activation='sigmoid')(conv9)

model = Model(inputs=[data], outputs=[conv10])
培训模型的代码如下所示:-

model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['binary_accuracy'])

目标标签的最后一个尺寸标注为2。模型的输出的最后一个维度为1。感谢@Shubham Panchal

目标标签的最后尺寸为2。模型的输出的最后一个维度为1。感谢@Shubham Panchal

我们需要一个损失函数
二进制交叉熵
用于UNet和乙状结肠激活
categorical\u crossentropy
用于多类分类。我更改了,但仍然得到相同的错误。我认为这个模型有问题。我不明白。@ShubhamPanchal任务是执行分段目标标签的最后一个维度为2。模型的输出的最后一个维度为1。也许目标标签是一个热编码的?@ShubhamPanchal噢,让我来编辑一下test@ShubhamPanchal感谢更改为二维后,模型运行。我们需要一个损失函数
binary\u crossentropy
用于UNet和sigmoid激活
categorical\u crossentropy
用于多类分类。我更改了,但仍然得到相同的错误。我认为这个模型有问题。我不明白。@ShubhamPanchal任务是执行分段目标标签的最后一个维度为2。模型的输出的最后一个维度为1。也许目标标签是一个热编码的?@ShubhamPanchal噢,让我来编辑一下test@ShubhamPanchal感谢更改为二维后,模型将运行。