patryg99 / hausdorffloss Goto Github PK
View Code? Open in Web Editor NEWImplementation of Hausdorff loss function for DNN learning in segmentation tasks.
Implementation of Hausdorff loss function for DNN learning in segmentation tasks.
Hello,
I have tried to use HausdirffDTLoss as Lossfunction.
However, the result for HausdirffDTLoss is too large.
For example:
output = np.zeros((3,3,512,512))
output[:,:,100:200,100:200] =1
output[:,:,300:500,300:500] =0.5
output_t = torch.tensor(output)
label = np.zeros((3,3,512,512))
label[:,:,100:200,100:200] =1
label_t = torch.tensor(label)
HD_loss =HausdorffDTLoss()
result = HD_loss(output_t,label_t)
the result is 6642.6849.
It is too huge.Did I do something wrong? Or do you have some method to normalize them into 0-1?
Thanks
Is it possible to train on GPU with HausdorffDTLoss
or HausdorffERLoss
?
How did you train for https://arxiv.org/pdf/1904.10030.pdf ?
I'm sorry to bother you.
I have a question,you use torch.no_grad()
in function distance_field
,The whole process is pre->pre_dt->loss
, Doesn't torch.no_grad()
truncate the gradient?Why add this operation can also be trained?Doesn't pred.cpu().numpy().float()
truncate the gradient?
I'm very confused about this and look forward to your reply and answer
Sorry for bothering you again. Recently, based on TransUnet, I am doing vessel image segmentation (the extreme imbalanced problem, the example of the ground truth is attached). I tried used the Hoausdorff Loss that you provided (total loss = loss_HD + alpha * loss_Dice, where alpha = mean(loss_HD)/mean(loss_Dice)) as described in the original paper.
The training loss curve is attached. In the first iteration, loss_HD = 4534 and loss_Dice = 0.55. In the second iteration, loss_HD = 0.0058 and loss_Dice = 0.5. In the third iteration, loss_HD = 0.0018 and loss_Dice = 0.5. In the training, I found that from the second iteration, all the prediction results are the background (i.e. the images are black, and it did not find the vessel). And in the testing process, all the prediction results are the background.
I have tried my best but still can not find where I am wrong. Could you please give me some advice? Is it because total loss can't handle extreme imbalance problem? Thanks.
I have a question regarding your 3D kernel shape.
The shape of your 3D kernel is 3, 1, 3, 3
I'm not sure but shouldn't the shape be 1, 3, 3, 3
? The first dimension should be the channel, followed by D x H x W or not? At the Moment your kernel is D x C x H x W if I'm not completely mistaken. The reason is:
self.kernel3D = np.array([bound, cross, bound]) * (1 / 7)
# should be
self.kernel3D = np.stack([bound, cross, bound], 1) * (1 / 7)
If the shape of the kernel is on purpose I would like to understand the idea behind it :)
Thanks a lot for your work.
Best regards,
Chris
Thanks so much for this wonderful work. I learned a lot from this work. But I have a question about it, i.e. in hausdorff_loss.py, there have:
def distance_field(self, img: np.ndarray) -> np.ndarray:
field = np.zeros_like(img)
for batch in range(len(img)):
fg_mask = img[batch] > 0.5
if fg_mask.any():
bg_mask = ~fg_mask
fg_dist = edt(fg_mask)
bg_dist = edt(bg_mask)
field[batch] = fg_dist + bg_dist
return field
My question is why field[batch] is the sum of fg_dist, bg_dist? The only fg_dist is not enough? Thank you in advance. Hope to hear from you as soon as possible.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.