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

[DEEP-180] Add mmsegmentation integration #2875

Merged
merged 15 commits into from
Jun 21, 2024
Merged

[DEEP-180] Add mmsegmentation integration #2875

merged 15 commits into from
Jun 21, 2024

Conversation

activesoull
Copy link
Contributor

@activesoull activesoull commented Jun 17, 2024

🚀 🚀 Pull Request

Impact

  • Bug fix (non-breaking change which fixes expected existing functionality)
  • Enhancement/New feature (adds functionality without impacting existing logic)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

added segmentation integration to deeplake. As a reference segmentation version is set the v0.30.0

install steps

git clone https://github.com/open-mmlab/mmsegmentation.git 
git checkout v0.30.0
cd mmsegmentation
python3 -m pip install -e .

Specify the config file

seg_mask_config.py

rom mmdet.apis import set_random_seed

_base_ = '/home/ubuntu/mmsegmentation/configs/pspnet/pspnet_r101-d8_512x512_4x4_160k_coco-stuff164k.py'

load_from = '/home/ubuntu/mmsegmentation/checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth'

img_norm_cfg = dict(
    mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)
crop_size = (256, 256)

reduce_zero_label=False

train_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(type='LoadAnnotations'),
    dict(type='Resize', img_scale=(320, 240), ratio_range=(0.5, 2.0)),
    dict(type='RandomCrop', crop_size=crop_size),
    dict(type='RandomFlip', flip_ratio=0.5),
    dict(type='PhotoMetricDistortion'),
    dict(type='Normalize', **img_norm_cfg),
    dict(type='Pad', size=crop_size, pad_val=0),
    dict(type='DefaultFormatBundle'),
    dict(type='Collect', keys=['img', 'gt_semantic_seg']),
    ]

test_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(
        type='MultiScaleFlipAug',
        img_scale=(320, 240),
        # img_ratios=[0.5, 0.75, 1.0, 1.25, 1.5, 1.75],
        flip=False,
        transforms=[
            dict(type='Resize', img_scale=(320, 240), keep_ratio=True),
            dict(type='RandomFlip'),
            dict(type='Normalize', **img_norm_cfg),
            dict(type='ImageToTensor', keys=['img']),
            dict(type='Collect', keys=['img']),
        ])
]

evaluation = dict(metric=["mIoU"], interval=500)

data = dict(
    samples_per_gpu=4,
    workers_per_gpu=8,
    train=dict(
        pipeline=train_pipeline,
        deeplake_path="hub://activeloop/coco-train-seg-mask",
        deeplake_tensors = {"img": "images", "gt_semantic_seg": "seg_masks"},
        deeplake_dataloader={"shuffle": False, "num_workers": 0, "drop_last": True}
    ),
    val=dict(
        pipeline=test_pipeline,
        deeplake_path="hub://activeloop/coco-val-seg-mask"",
        deeplake_tensors = {"img": "images", "gt_semantic_seg": "seg_masks"},
        deeplake_dataloader={"shuffle": False, "batch_size": 1, "num_workers": 0, "drop_last": True}
    )
)

deeplake_dataloader_type = "c++"

work_dir = "./work_exps"

optimizer = dict(lr=0.02 / 8)
lr_config = dict(warmup=None)
log_config = dict(interval=50)
checkpoint_config = dict(interval=1000)


seed = None
gpu_ids = range(2)


runner = dict(type="IterBasedRunner", max_iters=1000, max_epochs=None)

device = "cuda"

in integration, we kept the openmlab's naming conventions that is why deeplake export two apis build_segmentor and train_segmentor

specify entry point

train.py

import os
import torch

from mmcv import Config
import mmcv
from deeplake.integrations import mmseg as mmseg_deeplake
import os

# from pytorch_memlab import LineProfiler


if __name__ == "__main__":
    current_loc = os.getcwd()
    cfg_file = f"{current_loc}/seg_mask_config.py"
    validate = True
    distributed = True

    # Read the config file
    cfg = Config.fromfile(cfg_file)
    cfg.model.decode_head.num_classes = 81
    cfg.model.auxiliary_head.num_classes = 81

    # build segmentor
    model = mmseg_deeplake.build_segmentor(
        cfg.model
    )

    # train_segmentor
    mmseg_deeplake.train_segmentor(
        model,
        cfg,
        distributed=distributed,
        validate=validate
    )

@CLAassistant
Copy link

CLAassistant commented Jun 17, 2024

CLA assistant check
All committers have signed the CLA.

@activesoull activesoull changed the title Mmsegmentation [DEEP-180] Add mmsegmentation integration Jun 17, 2024
Copy link

codecov bot commented Jun 20, 2024

Copy link

sonarcloud bot commented Jun 21, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
6.2% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@tatevikh tatevikh merged commit 3f26e88 into main Jun 21, 2024
8 of 11 checks passed
@tatevikh tatevikh deleted the mmsegmentation branch June 21, 2024 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants