haoshao-nku / medical_seg

181 stars 21 forks source link

More than 2 classes when training Synapse dataset #5

Closed WuJuli closed 8 months ago

WuJuli commented 8 months ago

after /medical_seg/mmsegmentation/tools/dataset_converters/synapse.py , I used 3779 images to train, and it occured this error:

Traceback (most recent call last): File "tools/train.py", line 104, in main() File "tools/train.py", line 100, in main runner.train() File "/home/ubuntu/anaconda3/envs/medical_seg/lib/python3.8/site-packages/mmengine/runner/runner.py", line 1777, in train model = self.train_loop.run() # type: ignore File "/home/ubuntu/anaconda3/envs/medical_seg/lib/python3.8/site-packages/mmengine/runner/loops.py", line 278, in run self.run_iter(data_batch) File "/home/ubuntu/anaconda3/envs/medical_seg/lib/python3.8/site-packages/mmengine/runner/loops.py", line 301, in run_iter outputs = self.runner.model.train_step( File "/home/ubuntu/anaconda3/envs/medical_seg/lib/python3.8/site-packages/mmengine/model/base_model/base_model.py", line 114, in train_step losses = self._run_forward(data, mode='loss') # type: ignore File "/home/ubuntu/anaconda3/envs/medical_seg/lib/python3.8/site-packages/mmengine/model/base_model/base_model.py", line 346, in _run_forward results = self(data, mode=mode) File "/home/ubuntu/anaconda3/envs/medical_seg/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl return self._call_impl(*args, *kwargs) File "/home/ubuntu/anaconda3/envs/medical_seg/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl return forward_call(args, kwargs) File "/Storage/share/wwrrgg/medical_seg/mmsegmentation/mmseg/models/segmentors/base.py", line 94, in forward return self.loss(inputs, data_samples) File "/Storage/share/wwrrgg/medical_seg/mmsegmentation/mmseg/models/segmentors/encoder_decoder.py", line 178, in loss loss_decode = self._decode_head_forward_train(x, data_samples) File "/Storage/share/wwrrgg/medical_seg/mmsegmentation/mmseg/models/segmentors/encoder_decoder.py", line 139, in _decode_head_forward_train loss_decode = self.decode_head.loss(inputs, data_samples, File "/Storage/share/wwrrgg/medical_seg/mmsegmentation/mmseg/models/decode_heads/decode_head.py", line 262, in loss losses = self.loss_by_feat(seg_logits, batch_data_samples) File "/Storage/share/wwrrgg/medical_seg/mmsegmentation/mmseg/models/decode_heads/decode_head.py", line 324, in loss_by_feat loss[loss_decode.loss_name] = loss_decode( File "/home/ubuntu/anaconda3/envs/medical_seg/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl return self._call_impl(*args, *kwargs) File "/home/ubuntu/anaconda3/envs/medical_seg/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl return forward_call(args, *kwargs) File "/Storage/share/wwrrgg/medical_seg/mmsegmentation/mmseg/models/losses/cross_entropy_loss.py", line 286, in forward loss_cls = self.loss_weight self.cls_criterion( File "/Storage/share/wwrrgg/medical_seg/mmsegmentation/mmseg/models/losses/cross_entropy_loss.py", line 139, in binary_cross_entropy assert label[label != ignore_index].max() <= 1, \ AssertionError: For pred with shape [N, 1, H, W], its label must have at most 2 classes

haoshao-nku commented 8 months ago

We have recently discovered that while the mmsegmentation supports the synapse dataset, there are actually some bugs that cannot be resolved for the time being during training. We used a different framework to do this earlier, and we will update the synapse dataset code.

haoshao-nku commented 8 months ago

This problem you're talking about. Did you use the configuration file in the documentation? Or did you modify it yourself?

haoshao-nku commented 8 months ago

After checking, we found that the synapse configuration file in our project is incorrect and we will update it.

WuJuli commented 8 months ago

should I change loss function or something?

haoshao-nku commented 8 months ago

If you still want to implement other data sets using the multi-class mmsegmentation framework, we recommend that you refer to the implementation methods of other multi-class data sets in the mmsegmentation framework, such as the ade20k data set. Can reference/medical_seg mmsegmentation/configs/pspnet/pspnet_r50 - d8_4xb4-40 k_voc12aug - 512 x512.

haoshao-nku commented 8 months ago

Please wait while I update the synapse configuration file.

WuJuli commented 8 months ago

This problem you're talking about. Did you use the configuration file in the documentation? Or did you modify it yourself?

I did as you written in the datasets section, and I did not change other part of the code.

WuJuli commented 8 months ago

Please wait while I update the synapse configuration file. OKay! thank you!