CVI-SZU/CLIMS

irnet on coco

ProjectDisR opened this issue · 6 comments

irnet on coco

We got ~0.42 on COCO, similar with yours. I will try to upload the training code for deeplabv2 and hyper-params in this weekend. I‘m on a business trip :).

Hi @ProjectDisR, to train the deeplabv2 with coco, please follow the steps below

1.
add a dataset code in deeplabv2/libs/datasets/coco.py like

from __future__ import absolute_import, print_function

import os.path as osp
import cv2
import numpy as np
import torch
from PIL import Image
from torch.utils import data
import torchvision.datasets
from .base import _BaseDataset, _BaseDatasetTest, _BaseDatasetCotrain

class COCO(_BaseDataset):

    def __init__(self, label_dir=None, **kwargs):
        self.label_dir = label_dir
        super(COCO, self).__init__(**kwargs)
    
    def _set_files(self):
        if self.split in ["train", "test", "val"]:
            if self.split in ["val", "test"]:
                self.label_dir = osp.join(self.root, "mask", f"{self.split}2014")
            self.root = osp.join(self.root, f"{self.split}2014")
            ann_file = osp.join(self.root, f"../annotations/instances_{self.split}2014.json")
            self.coco = torchvision.datasets.CocoDetection(
                root=self.root, annFile=ann_file)
            file_list = self.coco.ids
            self.files = file_list
            # self.file_names = [self.coco.coco.imgs[_id]['file_name'] for _id in self.files]
        else:
            raise ValueError("Invalid split name: {}".format(self.split))
    
    def _load_data(self, index):
        image_id = self.files[index]
        # image_name = self.file_names[image_id]
        image_name = self.coco.coco.imgs[image_id]['file_name']
        image_path = osp.join(self.root, image_name)
        if self.split in ["val", "test"]:
            label_path = osp.join(self.label_dir, f"{image_id}.png")
        else:
            label_path = osp.join(self.label_dir, image_name.replace('.jpg', '.png'))
        image = cv2.imread(image_path, cv2.IMREAD_COLOR).astype(np.float32)
        label = np.asarray(Image.open(label_path), dtype=np.int32)
        return str(image_id), image, label

2.
And dont forget import it in deeplabv2/libs/datasets/__init__.py, like

...
from .coco import COCO

def get_dataset(name):
    return {
        ...
        "coco": COCO,
    }[name]

3.
We provide a template config file for coco, you should specify the data path before use

EXP:
    ID: coco14_clims_imagenet_pretrained
    OUTPUT_DIR: data

DATASET:
    NAME: coco
    ROOT: /path/to/your/COCO14
    LABEL_DIR: /path/to/your/pseudo/labels/
    LABELS: ./data/datasets/coco/labels.txt
    N_CLASSES: 81
    IGNORE_LABEL: 255
    SCALES: [0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0]
    SPLIT:
        TRAIN: train
        VAL: val
        TEST: test

DATALOADER:
    NUM_WORKERS: 0

IMAGE:
    MEAN:
        R: 122.675
        G: 116.669
        B: 104.008
    SIZE:
        BASE:
        TRAIN: 321
        TEST: 513

MODEL:
    NAME: DeepLabV2_ResNet101_MSC
    N_BLOCKS: [3, 4, 23, 3]
    ATROUS_RATES: [6, 12, 18, 24]
    INIT_MODEL: weights/deeplabv1_resnet101-imagenet.pth

SOLVER:
    BATCH_SIZE:
        TRAIN: 10
        TEST: 1
    ITER_MAX: 100000
    ITER_SIZE: 2
    ITER_SAVE: 5000
    ITER_TB: 100
    LR_DECAY: 10
    LR: 2.5e-4
    MOMENTUM: 0.9
    OPTIMIZER: sgd
    POLY_POWER: 0.9
    WEIGHT_DECAY: 5.0e-4
    AVERAGE_LOSS: 20

CRF:
    ITER_MAX: 10
    POS_W: 3
    POS_XY_STD: 1
    BI_W: 4
    BI_XY_STD: 67
    BI_RGB_STD: 3

After that, please train the deeplab for coco in the same way as for voc :)

Sorry for the late reply. You can try the instructions above.

We got ~0.42 on COCO, similar with yours. I will try to upload the training code for deeplabv2 and hyper-params in this weekend. I‘m on a business trip :).

Is this after applying crf to deeplab predictions ?

It's the quality of pseudo labels.