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

Troubleshooting LoadAnnotations Error with Channel Masks #2593

Closed
erdikilic opened this issue Feb 13, 2023 · 3 comments
Closed

Troubleshooting LoadAnnotations Error with Channel Masks #2593

erdikilic opened this issue Feb 13, 2023 · 3 comments
Assignees

Comments

@erdikilic
Copy link

I have three channel masks, each representing one of three classes. The masks have binary values of 0 and 1 for the background and target. Unfortunately, there are some conflicting areas in the masks that prevent me from using multi-class labeling. I am currently using the LoadAnnotations function to load the mask PNGs, but I am encountering an error. How can I resolve this issue?

Traceback (most recent call last):
File "/content/mmsegmentation/tools/train.py", line 106, in
main()
File "/content/mmsegmentation/tools/train.py", line 102, in main
runner.train()
File "/usr/local/lib/python3.8/dist-packages/mmengine/runner/runner.py", line 1686, in train
model = self.train_loop.run() # type: ignore
File "/usr/local/lib/python3.8/dist-packages/mmengine/runner/loops.py", line 263, in run
data_batch = next(self.dataloader_iterator)
File "/usr/local/lib/python3.8/dist-packages/mmengine/runner/loops.py", line 158, in next
data = next(self._iterator)
File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/dataloader.py", line 628, in next
data = self._next_data()
File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/dataloader.py", line 1333, in _next_data
return self._process_data(data)
File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/dataloader.py", line 1359, in _process_data
data.reraise()
File "/usr/local/lib/python3.8/dist-packages/torch/_utils.py", line 543, in reraise
raise exception
AssertionError: Caught AssertionError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/_utils/worker.py", line 302, in _worker_loop
data = fetcher.fetch(index)
File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/_utils/fetch.py", line 58, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/_utils/fetch.py", line 58, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/usr/local/lib/python3.8/dist-packages/mmengine/dataset/base_dataset.py", line 408, in getitem
data = self.prepare_data(idx)
File "/usr/local/lib/python3.8/dist-packages/mmengine/dataset/base_dataset.py", line 789, in prepare_data
return self.pipeline(data_info)
File "/usr/local/lib/python3.8/dist-packages/mmengine/dataset/base_dataset.py", line 58, in call
data = t(data)
File "/usr/local/lib/python3.8/dist-packages/mmcv/transforms/base.py", line 12, in call
return self.transform(results)
File "/content/mmsegmentation/mmseg/datasets/transforms/formatting.py", line 74, in transform
data_sample.gt_sem_seg = PixelData(**gt_sem_seg_data)
File "/usr/local/lib/python3.8/dist-packages/mmengine/structures/base_data_element.py", line 219, in init
self.set_data(kwargs)
File "/usr/local/lib/python3.8/dist-packages/mmengine/structures/base_data_element.py", line 249, in set_data
setattr(self, k, v)
File "/usr/local/lib/python3.8/dist-packages/mmengine/structures/pixel_data.py", line 78, in setattr
assert value.ndim in [
AssertionError: The dim of value must be 2 or 3, but got 4

@MeowZheng
Copy link
Collaborator

I think you can convert the segmentation masks of your dataset into single channel mask.
here is an example:

def iSAID_convert_from_color(arr_3d, palette=iSAID_invert_palette):

@erdikilic
Copy link
Author

Actually, single channel mask solution is not my case. As I mentioned before, some classes have joint masks. For example, a pixel target can be [0,1,1] as a result of three labels. But, I just wonder that, can I use LoadBiomedicalAnnotation to load multichannel masks for a PNG image with LoadImage?

@MeowZheng
Copy link
Collaborator

I fix it in #2739
LoadBiomedicalAnnotation is for 3D biomedical data, I think it is improper for your project

MeowZheng added a commit that referenced this issue Mar 14, 2023
Thanks for your contribution and we appreciate it a lot. The following
instructions would make your pull request more healthy and more easily
get feedback. If you do not understand some items, don't worry, just
make the pull request and seek help from maintainers.

## Motivation

fix #2593

## Modification

1. Only when gt seg map is 2D, extend its shape to 3D PixelData 
2. If seg map is not 2D, we raised warning for users.

---------

Co-authored-by: xiexinch <xiexinch@outlook.com>
aravind-h-v pushed a commit to aravind-h-v/mmsegmentation that referenced this issue Mar 27, 2023
* controlnet sd 2.1 checkpoint conversions

* remove global_step -> make config file mandatory
nahidnazifi87 pushed a commit to nahidnazifi87/mmsegmentation_playground that referenced this issue Apr 5, 2024
Thanks for your contribution and we appreciate it a lot. The following
instructions would make your pull request more healthy and more easily
get feedback. If you do not understand some items, don't worry, just
make the pull request and seek help from maintainers.

## Motivation

fix open-mmlab#2593

## Modification

1. Only when gt seg map is 2D, extend its shape to 3D PixelData 
2. If seg map is not 2D, we raised warning for users.

---------

Co-authored-by: xiexinch <xiexinch@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants