Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A fix so that you can weight specific pixels as in a 2D segmentation problem with only partially / weakly labeled pixels. #18

Open
isaacgerg opened this issue May 6, 2021 · 0 comments

Comments

@isaacgerg
Copy link

isaacgerg commented May 6, 2021

Let's assume 2D multi-category segmentation problem with batches are size [b, h, w, 1] and y_pred is [b,h,w,c] where c is number of classes.
Now, suppose you only have labels for some of the pixels, call this mask w and is of size [b,w,h] in {0,1} as an indicator variable if label not present / present.

Tf keras computes weighted metrics by loss() * w.

To have tf keras take advantage of this weight, you have to remove K.mean() from the end of the categorical loss. It should be just:

# Compute mean loss in mini_batch
return K.sum(loss, axis=-1)

This results in an output which is [b, w, h] which is the same as the shape of w.

@isaacgerg isaacgerg changed the title A fix so that you can weight specific pixels as in a 2D segmentation problem A fix so that you can weight specific pixels as in a 2D segmentation problem with only partially / weakly labeled pixels. May 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant