Giter VIP home page Giter VIP logo

Comments (6)

JianqiangWan avatar JianqiangWan commented on July 17, 2024 1

We define gt flux at each pixel as a two-dimensional unit vector pointing from its nearest boundary to the pixel. So gt flux around medial points have nearly opposite directions. It is difficult for neural networks to learn such sharp changes, and the network is more inclined to get a smooth transition (like from -1 to 1, network tend to output -1 -0.5 0 0.5 1).

For the norm loss, gt flux is a two-dimensional unit vector field, pred flux does not to be normalized.
For the angle loss, normalize pred flux inside or outside of torch.acos is the same.
image

from super-bpd.

JianqiangWan avatar JianqiangWan commented on July 17, 2024

Emmm, I am sorry for the confusion of norm gt (It is wrong, norm gt should be 1 at each pixel. Actually, it is a distance transform map). The calculation of gt flux can be seen in sec 3.1 of origin paper, returned gt_flux of datasets.py is not normalized by corresponding distance because the visualization of norm gt will be collapse.

Super-BPD/datasets.py

Lines 97 to 99 in 3c44638

diff = grid - nearPixel
direction_field[:, img > 0] = diff[:, img > 0]

So the normalization process is put in the loss calculation function.

from super-bpd.

rllin avatar rllin commented on July 17, 2024

thanks for the fast response @JianqiangWan !

however do you understand my concern with the pred_norm collapsing at unexpected places? perhaps I'm misunderstanding pred_norm?

from super-bpd.

rllin avatar rllin commented on July 17, 2024

i am also then confused that

Super-BPD/train.py

Lines 39 to 48 in 3c44638

gt_flux = 0.999999 * gt_flux / (gt_flux.norm(p=2, dim=1) + 1e-9)
# norm loss
norm_loss = weight_matrix * (pred_flux - gt_flux)**2
norm_loss = norm_loss.sum()
# angle loss
pred_flux = 0.999999 * pred_flux / (pred_flux.norm(p=2, dim=1) + 1e-9)
angle_loss = weight_matrix * (torch.acos(torch.sum(pred_flux * gt_flux, dim=1)))**2

gt_flux is normalized (because it was not in datasets.py) for the norm loss

but pred_flux is normalized for the angle loss and not the norm loss

from super-bpd.

rllin avatar rllin commented on July 17, 2024

thanks for the thorough response

let me make sure I understand:

  1. gt flux transitions directionality upon hitting the medial points. we can see this difficulty in learning sharp transitions in the difference between angle_gt and angle_pred: the transition from media to the boundary in angle_pred shows a gradient (like you mention -1 -0.5 0 0.5 1). your explanation makes sense to me for the angles and is born out by the actual behavior of the network.
  2. however, my primary concern is specifically with the norm component. my understanding is that these are direction agnostic, as seen in norm_gt where we see:
boundary ---- medial point ---- boundary
     0 1 2 3 4 5 6 7 6 5 4 3 2 1 0

however, we do not see that this is the case for norm_pred. the network seems to always predict:

boundary ---- medial point ---- boundary
     0 1 1 1 1 1 1 0 1 1 1 1 1 1 0

from super-bpd.

JianqiangWan avatar JianqiangWan commented on July 17, 2024

We need two channels (x, y) to express a flux field, gt flux around medial points can be roughly expressed as (x1, y1) and (-x1, -y1) since they have opposite direction.
image
From -x1 to x1 or -y1 to y1, network hardly gets the sharp transition, tending to get smooth transition.
norm = sqrt( x**2 + y**2), so pred norm between medial points (x to -x) or boundary points (-x to x) is very small, but the angle is still correct (we only use angle information for image segmentation).
Again, norm gt at each pixel is 1, 'norm gt' in the picture is a distance transform map before normalization.

from super-bpd.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.