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

半城伤御伤魂 提交于 2019-12-13 02:02:54

问题


I am using keras and python for satellite image segmentation. 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. 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?


回答1:


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. You find a lot of example implementations of it on github, e.g. here



来源:https://stackoverflow.com/questions/56006630/what-is-the-correct-way-to-reshape-image-segmentation-model-output-from-2d-num

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!