ge-xing / Diff-UNet

Diff-UNet: A Diffusion Embedded Network for Volumetric Segmentation. (using diffusion for 3D medical image segmentation)
Apache License 2.0
141 stars 20 forks source link

how can i change the input channel from 4 to 1 #2

Closed zhao9chen99999 closed 1 year ago

zhao9chen99999 commented 1 year ago

Hello, your work is so great!! i ve already got the results on brats2020,now iam work on my own datasets,but my dataset only have 1 modality (t1),i want to know where can i change the input channel from 4 to 1 ,and what else do i need to change,thx!!!!

920232796 commented 1 year ago

self.embed_model = BasicUNetEncoder(3, 4, 2, [64, 64, 128, 256, 512, 64])

self.model = BasicUNetDe(3, 7, 3, [64, 64, 128, 256, 512, 64], act = ("LeakyReLU", {"negative_slope": 0.1, "inplace": False}))

The second parameter of the two model is 4 and 7, respectively. If your dataset have 1 modality and 2 segmentation targets, you can modify the two number 4, 7 -> 1, 3. And the third parameter of BasicUNetDe is the number of segmentation targets. For example:

self.embed_model = BasicUNetEncoder(3, 1, 2, [64, 64, 128, 256, 512, 64])

self.model = BasicUNetDe(3, 3, 2, [64, 64, 128, 256, 512, 64], act = ("LeakyReLU", {"negative_slope": 0.1, "inplace": False}))

zhao9chen99999 commented 1 year ago

self.embed_model = BasicUNetEncoder(3, 4, 2, [64, 64, 128, 256, 512, 64])

self.model = BasicUNetDe(3, 7, 3, [64, 64, 128, 256, 512, 64], act = ("LeakyReLU", {"negative_slope": 0.1, "inplace": False}))

The second parameter of the two model is 4 and 7, respectively. If your dataset have 1 modality and 2 segmentation targets, you can modify the two number 4, 7 -> 1, 3. And the third parameter of BasicUNetDe is the number of segmentation targets. For example:

self.embed_model = BasicUNetEncoder(3, 1, 2, [64, 64, 128, 256, 512, 64])

self.model = BasicUNetDe(3, 3, 2, [64, 64, 128, 256, 512, 64], act = ("LeakyReLU", {"negative_slope": 0.1, "inplace": False}))

thanks for your answer!! my datasets have 1 modality and 1 segmentation targets(wt),does that means i need to adjust like: self.embed_model = BasicUNetEncoder(3, 1, 1, [64, 64, 128, 256, 512, 64])

self.model = BasicUNetDe(3, 2, 1, [64, 64, 128, 256, 512, 64],

920232796 commented 1 year ago

Yes.

zhao9chen99999 commented 1 year ago

Yes. i adjusted like this:

image

but i got this error report

image
WeiliJiang commented 1 year ago

Did you solve this problem?

ge-xing commented 1 year ago

You need to modify the dataset related codes to construct the right inputs. You can print the shape in this section:

image

And

sample_out = self.sample_diffusion.ddim_sample_loop(self.model, (1, 3, 96, 96, 96), model_kwargs={"image": image, "embeddings": embeddings}) The second parameter is (1, 3, 96, 96, 96), you may need to modify the 3 to 1 if your segmentation target number is 1.

WeiliJiang commented 1 year ago

you need to look the code at brats_data_utils_multi_label. as # transforms.ConvertToMultiChannelBasedOnBratsClassesD(keys=["label"]),

zhao9chen99999 commented 1 year ago

You need to modify the dataset related codes to construct the right inputs. You can print the shape in this section:

image

And

sample_out = self.sample_diffusion.ddim_sample_loop(self.model, (1, 3, 96, 96, 96), model_kwargs={"image": image, "embeddings": embeddings}) The second parameter is (1, 3, 96, 96, 96), you may need to modify the 3 to 1 if your segmentation target number is 1.

thx for you advice!!i'll try on that!!!

zhao9chen99999 commented 1 year ago

you need to look the code at brats_data_utils_multi_label. as # transforms.ConvertToMultiChannelBasedOnBratsClassesD(keys=["label"]),

thx for that,i'll have a try!

OCEANOUXIN commented 7 months ago

you need to look the code at brats_data_utils_multi_label. as # transforms.ConvertToMultiChannelBasedOnBratsClassesD(keys=["label"]),

thx for that,i'll have a try!

Hi! Do you successfully run the train.py after modify the input channel?

920232796 commented 7 months ago

You can see the BTCV dir, which has the single-channel input.

OCEANOUXIN commented 7 months ago

You can see the BTCV dir, which has the single-channel input.

Thanks for your reply.But I think I don't catch your meaning.

920232796 commented 7 months ago

https://github.com/ge-xing/Diff-UNet/blob/main/BTCV/train.py

This file contains the example of single-channel input.

OCEANOUXIN commented 6 months ago

https://github.com/ge-xing/Diff-UNet/blob/main/BTCV/train.py

This file contains the example of single-channel input.

hello, I find it the train results of my own dataset are not good, and the test out is not correct.

zhao9chen99999 commented 6 months ago

I have already received your e-mail,Thanks a lot!我已收到您发送的邮件,感谢您的来信!

OCEANOUXIN commented 6 months ago

https://github.com/ge-xing/Diff-UNet/blob/main/BTCV/train.py

This file contains the example of single-channel input.

image I don't know why the valdation process takes so long...

OCEANOUXIN commented 6 months ago

https://github.com/ge-xing/Diff-UNet/blob/main/BTCV/train.py

This file contains the example of single-channel input.

I modify this : image image image image

the result is not ideal.

920232796 commented 6 months ago

You can contact with me on the wechat: 18340097191. Thank you!