简体   繁体   English

用于3D语义分割任务的Keras预处理

[英]Keras preprocessing for 3D semantic segmentation task

For semantic image segmentation, I understand that you often have a folder with your images and a folder with the corresponding masks. 对于语义图像分割,我知道您经常有一个包含图像的文件夹和一个具有相应遮罩的文件夹。 In my case, I have gray-scale images with the dimensions (32, 32, 32). 就我而言,我有尺寸为(32、32、32)的灰度图像。 The masks naturally have the same dimensions. 掩模自然具有相同的尺寸。 The labels are saved as intensity values (value 1 = label 1, value 2 = label 2 etc.). 标签将保存为强度值(值1 =标签1,值2 =标签2等)。 4 classes in total. 共4节课。 Imagine I have found a model that was built with the keras model API. 想象一下,我发现了一个使用keras模型API构建的模型。 How do I know how to prepare my label data for it to be accepted by the model? 我如何知道如何准备标签数据以供模型接受? Does it depend on the loss function? 是否取决于损失函数? Is it defined in the model (Input parameter). 是否在模型中定义(输入参数)。 Do I just add another dimension (4, 32, 32, 32) in which the 4 represents the 4 different classes and one-hot code it? 我是否只需添加另一个维度(4、32、32、32),其中4代表4个不同的类和一个热门代码呢?

I want to build a 3D convolutional neural network for semantic segmentation but I fail to understand how to feed in the data correctly in keras. 我想建立一个用于语义分割的3D卷积神经网络,但是我不明白如何正确地在keras中输入数据。 The predicted output is supposed to be a 4-channel 3D image, each channel showing the probability values of each pixel to belong to a certain class. 预测的输出应该是4通道3D图像,每个通道显示每个像素属于某个类别的概率值。

The Input() function defines the shape of the input tensor of a given model. Input()函数定义给定模型的输入张量的形状。 For 3D images, often a 5D Tensor is expected, eg (None, 32, 32, 32, 1) , where None refers to the batch size. 对于3D图像,通常需要5D张量,例如(None, 32, 32, 32, 1) ,其中“无”是指批量大小。 Therefore the training images and labels have to be reshaped. 因此,训练图像和标签必须重塑。 Keras offers the to_categorical function to one-hot encode the label data (which is necessary). to_categorical提供to_categorical函数对标签数据进行一次热编码(这是必需的)。 The use of generators helps to feed in the data. 生成器的使用有助于输入数据。 In this case, I cannot use the ImageDataGenerator from keras as it can only deal with RGB and grayscale images and therefore have to write a custom script. 在这种情况下,我不能使用来自keras的ImageDataGenerator,因为它只能处理RGB和灰度图像,因此必须编写自定义脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM