Comments (1)
Hey there,
The code is a little bit more convoluted that needed, because I used the same codebase for my other works (namely https://github.com/LIVIAETS/SizeLoss_WSS, but you can checkout the other repo in the organization).
Which means I have to handle of following cases:
- Varying number of losses, with different weights and parameters for each one
- Losses with and without bounds to enforce
Right now all my losses use either the label or the bounds, but that might change in the future so I kept functions that take the two as an input.
In the boundary loss paper, the distance map are labels transformed in a different way:
gt_transform = transforms.Compose([
lambda img: np.array(img)[np.newaxis, ...],
lambda nd: torch.tensor(nd, dtype=torch.int64),
partial(class2one_hot, C=n_class),
itemgetter(0)
])
dist_map_transform = transforms.Compose([
lambda img: np.array(img)[np.newaxis, ...],
lambda nd: torch.tensor(nd, dtype=torch.int64),
partial(class2one_hot, C=n_class),
itemgetter(0),
lambda t: t.cpu().numpy(),
one_hot2dist,
lambda nd: torch.tensor(nd, dtype=torch.float32)
])
(you will notice that the distmap transform is a continuation of the gt_transform)
the data folders are defined like this:
B_DATA = [('in_npy', torch.tensor, False), ('gt_npy', gt_transform, True)]
results/wmh/gdl_surface_steal: DATA = --folders="$(B_DATA)+[('gt_npy', gt_transform, True), \
('gt_npy', dist_map_transform, False)]"
which gives 4 tensors as output of the dataloader:
- in_npy, the input image, which is simply loaded and fed to the network
- gt_npy, the labels, used to compute the metrics
- gt_npy, the labels, used this time for the loss using them (GDL in this case)
- gt_npy, with the dist_map transform, used for the boundary loss
Then, the losses are defined this way
results/wmh/gdl_surface_steal: OPT = --losses="[('GeneralizedDice', {'idc': [0, 1]}, None, None, None, 1), \
('SurfaceLoss', {'idc': [1]}, None, None, None, 0.01)]"
The three consecutive None
correspond to the options for the bounds:
- The method to generate the bounds (constant, dependent on the data, predictive...)
- The options for the generation
- What function to constraint (size, centroid, ...)
You can find one working example here https://github.com/LIVIAETS/SizeLoss_WSS/blob/master/acdc.make#L149 if you are interested.
So, to summarize, there is no mistake, as we end up with two losses:
- GDL, which takes as input the label transformed with
gt_transform
- surface loss, which takes as input the label transformed with
dist_map_transform
Both of them ignore the provided bounds.
Let me know if some part was not clear,
Hoel
from boundary-loss.
Related Issues (20)
- Does einsum really make the code easier to understand HOT 2
- ISLES 2018 HOT 1
- Heterogeneous resolution yields non-zero boundary. HOT 5
- InvalidArgumentError: required broadcastable shapes at loc(unknown) [Op:Mul] HOT 2
- Can this loss be used for multi-label classification? HOT 4
- Create dist_map for image segmentation mask as label. HOT 2
- Is multiplication by negmask in one_hot2dist() irrelevant? HOT 2
- Question about the optional argument resolution in the dist_map_transform function HOT 1
- About the calculation of dist_map HOT 5
- how to use with sigmoid as activation function when meeting binary classification segmentation task HOT 3
- how to adjust the lambda parameter HOT 5
- How to use HausdorffLoss? HOT 1
- How to use HausdorffLoss? HOT 1
- How to one-hot encode a multi-class dataset and how to use Boundary Loss on B x N x W x H logits? HOT 2
- Only using boundary loss leads to non convergence HOT 1
- Failure of matching datasets of WMH HOT 1
- Is it possible to train the Boundary Loss code on a GPU? HOT 1
- Whether this loss function can be applied to the partition of a hollow region, that is, a region with two boundaries HOT 2
- License Request
- zero question
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from boundary-loss.