简体   繁体   English

将2D(类数,像素数)输出的图像分割模型重塑为3D通道最后一张图像的正确方法是什么

[英]what is the correct way to reshape image segmentation model output from 2D (num of classes, num of pixels) to 3D channel last images

I am using keras and python for satellite image segmentation. 我正在使用keras和python进行卫星图像分割。 It is my understanding that to get (pixel level)predictions for image segmentation, model reshapes layer of dimension(-1,num_classes,height,width) to shape (-1,num_classes,height*width).This is then followed by applying activation function like softmax or sigmoid. 据我了解,要获得图像分割的(像素级)预测,模型会将尺寸(-1,num_classes,height,width)的图层重塑为(-1,num_classes,height * width)的形状,然后再应用激活功能,例如softmax或Sigmoid。 My question is how to recover images after this step back in the format either channel first or channel last? 我的问题是在此步骤后以通道优先或通道末尾的格式恢复图像? example code 示例代码

o = (Reshape((  num_classes , outputHeight*outputWidth)))(o)
o = (Permute((2, 1)))(o)
o = (Activation('softmax'))(o)

I have tried adding following layer to the model at the end 我试图在最后添加以下图层到模型

o = (Reshape((outputHeight, outputWidth, num_classes)))(o)

Is this correct? 这个对吗? will this reorient the image pixels in the same order as original or not? 这会以与原始顺序相同的顺序重新定向图像像素吗? Another alternative may be to use following code on individual images. 另一种选择是在单个图像上使用以下代码。

array.reshape(height, width, num_classes)

Which method should i use to get pixel level segmentation result? 我应该使用哪种方法来获得像素级分割结果?

No, if you are interested in an image segmentation, you should not flatten and then reshape your tensors. 不,如果你有兴趣的图像分割, 应该压平,然后重塑你的张量。 Instead, use a fully convolutional model, like the U-Net . 而是使用完全卷积模型,例如U-Net You find a lot of example implementations of it on github, eg here 您可以在github上找到很多示例实现,例如, 这里

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

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