akirasosa / mobile-semantic-segmentation

Real-Time Semantic Segmentation in Mobile device
MIT License
715 stars 135 forks source link

Variable classes #31

Closed jbmaxwell closed 6 years ago

jbmaxwell commented 6 years ago

I can't see any way to define the number of classes detected. How would I increase the number of classes?

EDIT: It seems to me it should be the last conv2D layer in the model; that is, changing Conv2D(1, (1,1) ...)(b18) to Conv2D(num_classes, (1,1) ...)(b18). Of course, this gives me a shape mismatch error. Ideally, I'd like my output to be a (1, height, width) matrix where each value indicates the inferred class for that pixel (i.e., as the most highly activated channel for that pixel). I'm pretty new to keras, so any thoughts appreciated.

jbmaxwell commented 6 years ago

I guess the other option would be to convert my images - which are (1, h, w), with pixels values representing the class number - to (num_classes, h, w), with each channel representing a single one-hot coded class... So the last activation layer should output (batches, num_classes, h, w)... (though the model summary prints this as (None, h, w, num_classes)).

NOTE: I would think that multi-class should also probably use softmax instead of sigmoid...

akirasosa commented 6 years ago

Yes. The output shape will be something like (n_batch, h, w, n_classes). Then, apply softmax loss across last dimension.

If I have time, I will add example to segment hair, face and background.