Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert label.max() == self.num_classes-1, label.max() #24

Open
MasterEndless opened this issue Dec 10, 2024 · 6 comments
Open

assert label.max() == self.num_classes-1, label.max() #24

MasterEndless opened this issue Dec 10, 2024 · 6 comments

Comments

@MasterEndless
Copy link

作者您好!
我在用您的代码跑实验的时候遇到了这个错误,training可以正常运行10个epoch,在validation的时候崩了,具体error为:

File "/home/server1/Documents/MedSoK/Stable-Diffusion-Seg/main.py", line 405, in log_img
metrics_dict, seg_label_dict = pl_module.log_dice()
File "/home/server1/Documents/hanliu/miniconda3/envs/sdseg/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/home/server1/Documents/MedSoK/Stable-Diffusion-Seg/ldm/models/diffusion/ddpm.py", line 1688, in log_dice
ema_dice, ema_iou, seg_label_pair = get_dice(data, used_sampler="direct", save_dir=save_dir)
File "/home/server1/Documents/MedSoK/Stable-Diffusion-Seg/ldm/models/diffusion/ddpm.py", line 1682, in get_dice
ema_dice_list, ema_iou_list, seg_label_pair = get_dice_loop(data, sampler,
File "/home/server1/Documents/MedSoK/Stable-Diffusion-Seg/ldm/models/diffusion/ddpm.py", line 1390, in get_dice_loop
assert label.max() == self.num_classes-1, label.max()
AssertionError: tensor(-1.)

我用的命令是:
nohup python -u main.py --base configs/latent-diffusion/synapse-cls2-ldm-kl-8.yaml -t --gpus 0, --name normal > nohup/normal.log 2>&1

数据集为BTCV,看上去是label最大值为-1了,是数据载入的问题。config文件里我把test的config改了,因为不改的话找不到数据,并且我吧BTCV的数据放在了./Stable-Diffusion-Seg/data/synapse/train和./Stable-Diffusion-Seg/data/synapse/test下,具体config为:

data:
target: main.DataModuleFromConfig
params:
batch_size: 4
num_workers: 8
wrap: False
train:
target: ldm.data.synapse.SynapseTrain
params:
size: 256
validation:
target: ldm.data.synapse.SynapseValidation
params:
size: 256
test:
target: ldm.data.synapse.SynapseValidation
params:
size: 256

提前感谢您的帮助!

@MasterEndless
Copy link
Author

comment了这一行后assert label.max() == self.num_classes-1, label.max()
运行正常,不知道会不会影响performance

@lin-tianyu
Copy link
Owner

lin-tianyu commented Dec 11, 2024

哈喽,谢谢你提供了很详细的信息来帮助我分析。

我想要指出,你把

test:
target: ldm.data.synapse.SynapseValidationVolume

修改成

test:
target: ldm.data.synapse.SynapseValidation

是不正确的,尽管能够跑通。这是因为:SynapseValidationVolume是用来加载3D格式的CT数据的,而SynapseValidation读取的是CT数据的切片。而二者在计算指标的时候会被自动分为3D的计算方式和2D的计算方式,从而导致你所得到的指标结果与论文里的不一致(我自己就踩过这个坑,2D算指标会比3D低10个点左右)。

而之所以为什么“config文件里我把test的config改了,因为不改的话找不到数据”,这个是因为这些测试的3D volume不需要进行预处理,因此没有写在预处理的脚本当中。实际上,应该要手动将这几个volume复制粘贴到test_vol目录下。(因为这步非常简单,我就没有在预处理脚本中体现,也缺少了相关说明,这是我的问题~)

我的建议是你先按照我这里说的来重新处理一下数据集(不需要修改config文件),然后再看看会不会出现“label最大值为-1了,是数据载入的问题”这些错误。理应是不会的。

祝好!

@MasterEndless
Copy link
Author

MasterEndless commented Dec 11, 2024

感谢您的回答!请问测试的3D volume在哪里找到呢,我根据您的指示下载 BTCV dataset: Abdomen/RawData.zip.
然后用./data/synapse/nii2format.py进行预处理,把预处理后的所有文件都放在了data/synapse下面。RawData下面貌似都是压缩文件

RawData/Testing/img$ ls
img0061.nii.gz img0064.nii.gz img0067.nii.gz img0070.nii.gz img0073.nii.gz img0076.nii.gz img0079.nii.gz
img0062.nii.gz img0065.nii.gz img0068.nii.gz img0071.nii.gz img0074.nii.gz img0077.nii.gz img0080.nii.gz
img0063.nii.gz img0066.nii.gz img0069.nii.gz img0072.nii.gz img0075.nii.gz img0078.nii.gz

感谢您的帮助!

@lin-tianyu
Copy link
Owner

lin-tianyu commented Dec 11, 2024 via email

@lin-tianyu
Copy link
Owner

所使用的测试集volume在nii2format.py中:

@MasterEndless
Copy link
Author

这些.nii.gz文件就是3D volume呀 nii2format.py中应该有记录所使用的测试集volume是哪些 Tianyu Lin Master of Science in Biomedical Engineering Whiting School of Engineering, Johns Hopkins University

________________________________ From: Han Liu @.> Sent: Tuesday, December 10, 2024 9:23:55 PM To: lin-tianyu/Stable-Diffusion-Seg @.> Cc: Tianyu Lin @.>; Comment @.> Subject: Re: [lin-tianyu/Stable-Diffusion-Seg] assert label.max() == self.num_classes-1, label.max() (Issue #24) 感谢您的回答!请问测试的3D volume在哪里找到呢,我根据您的指示下载 BTCV dataset: Abdomen/RawData.zip. 然后用./data/synapse/nii2format.py进行预处理,把预处理后的所有文件都放在了data/synapse下面。RawData下面貌似都是压缩文件 RawData/Testing/img$ ls img0061.nii.gz img0064.nii.gz img0067.nii.gz img0070.nii.gz img0073.nii.gz img0076.nii.gz img0079.nii.gz img0062.nii.gz img0065.nii.gz img0068.nii.gz img0071.nii.gz img0074.nii.gz img0077.nii.gz img0080.nii.gz img0063.nii.gz img0066.nii.gz img0069.nii.gz img0072.nii.gz img0075.nii.gz img0078.nii.gz 感谢您的帮助! ― Reply to this email directly, view it on GitHub<#24 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ARUIAEO4MMIE7TSKQVKPAGT2E7D6XAVCNFSM6AAAAABTKLT7HSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMZTGY3DMOJQG4. You are receiving this because you commented.Message ID: @.***>

谢谢!我把test文件copy过去后确实测试集上的表现提升了很多
image
不过assert label.max() == self.num_classes-1, label.max()问题仍然存在,我把这一行comment掉了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants