HuXiaoling / TopoLoss

Code for the NeurIPS 2019 paper: Topology-Preserving Deep Image Segmentation
MIT License
146 stars 22 forks source link

Error in constructor Bitmap_cubical_complex_base #9

Closed onealbao closed 2 years ago

onealbao commented 2 years ago

Hello, thanks so much for sharing this decent work. I'm trying to integrate the topoloss_pytorch.py into deeplab_v3 (https://github.com/chenxi116/DeepLabv3.pytorch).

The target tensor is [ 0 1 255] b/c my label only has background (0) and membrane label (1), 255 is ignored when calculating CrossEntropyLoss. The output tensor is a probability map with a value something like [-43.70812 -43.228703 -42.97284 ... 54.40196 54.60862 55.549427].

When I tried to input the target and output tensor into the topoloss, the whole pipeline crashed with the following error.

Error in constructor Bitmap_cubical_complex_base ( std::vector<std::size_t> sizes_in_following_directions, std::vector<T> top_dimensional_cells ). Number of top dimensional elements that follow from sizes_in_following_directions vector is different than the size of top_dimensional_cells vector.
terminate called after throwing an instance of 'char const*'
Aborted

It seems that the error is from

# Get the critical points of predictions and ground truth
pd_lh, bcp_lh, dcp_lh, pairs_lh_pa = getCriticalPoints(lh_patch)

but there is no further instruction. Have you ever seen this exception? Many thanks!

HuXiaoling commented 2 years ago

Sorry that I didn't come across this kind of errors before. Would you please try to test your tensors/images with this offline version topoloss first? If you still have any problems, please try to post them here.

onealbao commented 2 years ago

Thanks so much for the prompt feedback. I've tried the offline version of topoloss, but got the same error about 'Error in constructor Bitmap_cubical_complex_base'.

It seems that the exception is from https://github.com/HuXiaoling/TopoLoss/blob/bbf9d2699cbd76dabe113e8be810c56aa40a8e06/topoloss.py#L114

I've forked your repository and uploaded two sample images (gt.png and out.png) there for testing purposes at https://github.com/onealbao/TopoLoss. Maybe there is something wrong with my data input? Thanks a ton!

onealbao commented 2 years ago

Quick update, it looks like the problem is because of my label value. The segmentation line needs to be 255 and the background is 0. The offline version works. I'll try the PyTorch version and back to post here then, thanks!

HuXiaoling commented 2 years ago

10 Sorry for this bug. Please try to use the correct version.