rstrudel / segmenter

[ICCV2021] Official PyTorch implementation of Segmenter: Transformer for Semantic Segmentation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

customised data

Remosy opened this issue · comments

commented

Hello,

i wanna try this on my own dataset, i have created similar config files and python files like you did for ade20k.

I added a class file for my dataset:

FISH_CONFIG_PATH = Path(__file__).parent / "config" / "fish.py"
FISH_CATS_PATH = Path(__file__).parent / "config" / "fish.yml"

@DATASETS.register_module
class FishSegmentation(BaseMMSeg):
    def __init__(self, image_size, crop_size, split, **kwargs):
        super().__init__(
            image_size, crop_size, split, 
            config_path = FISH_CONFIG_PATH,
            normalization=kwargs.pop('normalization')
        )
        self.names, self.colors = utils.dataset_cat_description(FISH_CATS_PATH)
        self.n_cls = 3
        self.ignore_label = 0
        self.reduce_zero_label = True

After i registered my data by @DATASETS.register_module, the init founction is kind of conflicted with your BaseMMSeg, is there any way that I can use customised data based on your repo?

commented

I have solved above problems and used my data in the model.

First, edit inside mmseg

  • I added my data as ADE data did inside : 'C:\ProgramData\Anaconda3\envs\segmenter\Lib\site-packages\mmseg\datasets_init_.py'
  • Then I copied ADE python file inside C:\ProgramData\Anaconda3\envs\segmenter\Lib\site-packages\mmseg\datasets , and edit the copied file based on my data

Second, edit inside the code by adding my own data

├── trainFish.py
├── data
│   ├── fish.py (FishSegmentation)
│   ├── config
|        ├── fish.yml 
|        ├── fish.py
│   ├── factory.py (added choises)
│   ├── __init__ (added customised class)

added my data inside segm/config.yml

fish:
    epochs: 64
    eval_freq: 4
    batch_size: 8
    learning_rate: 0.001
    im_size: 1280
    crop_size: 1280
    window_size: 1280
    window_stride: 720

After doing above, I still cannot run it as I supposed. Although my data has only 3 classes, I can only train normally when set the self.n_cls >= 150 (it is totally same as ADE repo) inside my own segm/data/fish.py. Otherwise, an error would occured:

Assertion t >= 0 && t < n_classes failed.

My backbone: vit_tiny_patch16_384

@Remosy Did you happen to have a checkpoint saved where it was trying to load weights with a different n_cls count?

commented

@Remosy Did you happen to have a checkpoint saved where it was trying to load weights with a different n_cls count?
Thx! I just found out my bug was caused by wrong annotation mask.

commented

I tried another light datset (https://www.kaggle.com/bulentsiyah/semantic-drone-dataset), and I can use this paper's code succesully. I tried DEIT and Vit-tiny two versions. It turned out that Vit-tiny performed better than DEIT in my case.

@Remosy Could you share how you solved the error Assertion t >= 0 && t < n_classes failed? I have encountered the same problem but can not find where my annotations are wrong.

commented

@Remosy Could you share how you solved the error Assertion t >= 0 && t < n_classes failed? I have encountered the same problem but can not find where my annotations are wrong.

My problem was caused by falsely annotated images. I used 8-bit grayscale PNG images, but the pixel range was incorrect as it ranged from 0 to 255. To correct this, I mapped the pixel values of my annotated images to corresponding classes. For instance, I had three types of fish labeled with the colors red, green, and blue. I then changed the red area to 1, green area to 2, blue area to 3, and all other backgrounds to 0. Consequently, the annotation image only had 4 types of pixel values: 0, 1, 2, and 3.

I see, thank you for the explanation

commented

How is the.yml file set up in data?My data set has only one class of objects and backgrounds.
I set it as follows:

  • color:
    • 127
    • 0
    • 0
      id: 0
      isthing: 0
      name: oil
  • color:
    • 0
    • 0
    • 0
      id: 1
      isthing: 0
      name: background
      I set ncls=2, my losses keep going down but my mIOU stays the same. This question has been bothering me for a long time. Looking forward to your reply.

@sym330 My .yml file is like:

  • color:

    • 0
    • 0
    • 0
      id: 0
      name: background
  • color:

    • 255
    • 0
    • 0
      id: 1
      name: drusa
  • color:

    • 0
    • 255
    • 0
      id: 2
      name: puede-drusa

    Your file seems correct to me. The only thing i would suggest is to set the background class to id 0, and foreground to id 1.
    The data file for my dataset has the following parameters:

    self.names, self.colors = utils.dataset_cat_description(FINAL_DATASET_CATS_PATH)
    self.n_cls = 3
    self.ignore_label = 255
    self.reduce_zero_label = False

If you have everything configured correctly, maybe you should change your loss function or add weights to it. I hope this helps!

commented

I soved it, thank you!!! by removing "reduce_label_zero=True"