I want to performing multiclass semantic segmentation. My images are grayscale.
image:(256,256,1)
I tried one hot encoding for multiclass segmentation and it works. The shape of my mask or target looks like this after one hot encoding. I have 8 classes.
mask:(256,256,8)
But one hot encoding is causing me memory error since my GPU cannot handle it and so I need to switch to another loss function which is sparse_categorical_crossentropy. But I am not sure how to encode my target for this.
I read that sparse entropy has only integer targets. I labelled my class names in categories such as 'defect1', 'defect2', 'defect3' etc.
But how do i encode my target labels for this entropy. Is it just a single list of target values? How should it look like when i feed it into the network?
Is there any particular encoding method to perform this? or any example of how the target should look like?
I am creating the dataset of images and target myself(custom dataset) so I did the annotations and labelled it. I am using U-net architecture.
I tried having my target to be (256,256)
and last layer with out=layers.Conv2D(9,1,activation='softmax')(previous_layer)
. 9 is the number of classes. With this i am getting shape error
valueError: Error while checking target:expected output to have 4 dimensions but got array with shape (None,256,256).
I tried also the answers in the following link
So kept target shape to be (256*256,1)
and used reshaping of last layer.
out=layers.Conv2D(9,1,activation='softmax')(previous_layer)
reshape=layers.Reshape((256*256,9))(out)
and this works but I am not sure if this implementation is correct because of the multiplication of image size how can a prediction be made and how to map the labels? My data is heavily imbalanced but still it shows accuracy around 0.995
question from:
https://stackoverflow.com/questions/65599414/how-to-prepare-targets-for-sparse-categorical-entropy 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…