Deep-ML | The U-Net Weight Map: Class Balance Plus a Penalty on Separation BordersThe U-Net Weight Map: Class Balance Plus a Penalty on Separation Borders
The U-Net Weight Map: Class Balance Plus a Penalty on Separation Borders
The pixel in the one-pixel gap between the two cells is at distance 1 from both, so it gets almost the full extra weight 10 on top of the background's class weight; the far corner and the background next to only one cell get little extra, and a cell pixel gets the foreground class weight alone.
The U-Net Weight Map: Class Balance Plus a Penalty on Separation Borders
To teach the network the thin background gaps between touching cells, U-Net weights each pixel of the loss by
w(x)=wc(x)+w0exp(−2σ2(d1(x)+d2(x))2),
with w0=10 and σ=5 pixels in the paper. Compute this map from an instance label image.
Input: instances, an integer array (H,W): 0 is background, and each positive value marks the pixels of one cell (labels need not be consecutive).
Class-balance term wc (the paper does not give its formula; use this one): with n=HW pixels, k the number of classes present among {background, foreground} (1 or 2), and nc the number of pixels in the class of x,
wc(x)=kncn.
Border term, at background pixels only:
di(x) is the Euclidean distance from pixel x to the nearest pixel of cell i, measured between pixel centres (a background pixel next to a cell has distance 1, a diagonal neighbour 2).
d1(x) and d2(x) are the smallest and second smallest of these distances over the cells, so they always come from two different cells.
With fewer than two cells the border term is 0. Cell pixels get wc only.
Output: the weight map, a float array of shape (H,W).