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

Modified ddrnet. Hello, I made some small modifications to ddrnet in my own experiments and later wanted to inference these models in the model hardware library (https://platform.openmmlab.com/deploee/), so I submit this PR. #3432

Open
wants to merge 6 commits into
base: dev-1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 8 additions & 64 deletions .pre-commit-config.yaml
@@ -1,66 +1,10 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: flake8
- repo: https://github.com/zhouzaida/isort
rev: 5.12.1
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-yapf
rev: v0.32.0
hooks:
- id: yapf
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: check-yaml
- id: end-of-file-fixer
- id: requirements-txt-fixer
- id: double-quote-string-fixer
- id: check-merge-conflict
- id: fix-encoding-pragma
args: ["--remove"]
- id: mixed-line-ending
args: ["--fix=lf"]
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.9
hooks:
- id: mdformat
args: ["--number"]
additional_dependencies:
- mdformat-openmmlab
- mdformat_frontmatter
- linkify-it-py
- repo: https://github.com/codespell-project/codespell
rev: v2.2.1
hooks:
- id: codespell
- repo: https://github.com/myint/docformatter
rev: v1.3.1
hooks:
- id: docformatter
args: ["--in-place", "--wrap-descriptions", "79"]
# temporarily remove update-model-index to avoid conflict raised
# by depth estimator models
# - repo: local
# hooks:
# - id: update-model-index
# name: update-model-index
# description: Collect model information and update model-index.yml
# entry: .dev_scripts/update_model_index.py
# additional_dependencies: [pyyaml]
# language: python
# require_serial: true
- repo: https://github.com/asottile/pyupgrade
rev: v3.0.0
hooks:
- id: pyupgrade
args: ["--py36-plus"]
- repo: https://github.com/open-mmlab/pre-commit-hooks
rev: v0.2.0 # Use the rev to fix revision
hooks:
- id: check-algo-readme
- id: check-copyright
args: ["mmseg", "tools", "tests", "demo"] # the dir_to_check with expected directory to check
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
76 changes: 76 additions & 0 deletions configs/_base_/datasets/feces.py
@@ -0,0 +1,76 @@
# dataset settings
dataset_type = 'Feces'
data_root = 'D:\Allcode\mmsegmentation-dev-1.x\data\data'
img_scale = (448, 224)
crop_size = (224, 224)
train_pipeline = [
dict(type='LoadImageFromFile'),
dict(type='LoadAnnotations'),
dict(
type='RandomResize',
scale=img_scale,
ratio_range=(0.5, 2.0),
keep_ratio=True),
dict(type='RandomFlip', prob=0.7),
dict(type='PhotoMetricDistortion'),
dict(type='RandomCrop', crop_size=crop_size, cat_max_ratio=0.75),
dict(type='PackSegInputs')
]
test_pipeline = [
dict(type='LoadImageFromFile'),
dict(type='Resize', scale=img_scale, keep_ratio=True),
# add loading annotation after ``Resize`` because ground truth
# does not need to do resize data transform
dict(type='LoadAnnotations'),
dict(type='PackSegInputs')
]

img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=None),
dict(
type='TestTimeAug',
transforms=[
[
dict(type='Resize', scale_factor=r, keep_ratio=True)
for r in img_ratios
],
[
dict(type='RandomFlip', prob=0., direction='horizontal'),
dict(type='RandomFlip', prob=1., direction='horizontal')
], [dict(type='LoadAnnotations')], [dict(type='PackSegInputs')]
])
]

train_dataloader = dict(
batch_size=64,
num_workers=4,
persistent_workers=True,
sampler=dict(type='InfiniteSampler', shuffle=True),
dataset=dict(
type='RepeatDataset',
times=40000,
dataset=dict(
type=dataset_type,
data_root=data_root,
data_prefix=dict(
img_path='images/training',
seg_map_path='annotations/training'),
pipeline=train_pipeline)))
val_dataloader = dict(
batch_size=1,
num_workers=2,
persistent_workers=True,
sampler=dict(type='DefaultSampler', shuffle=False),
dataset=dict(
type=dataset_type,
data_root=data_root,
data_prefix=dict(
img_path='images/validation',
seg_map_path='annotations/validation'),
pipeline=test_pipeline))
test_dataloader = val_dataloader

val_evaluator = dict(
type='IoUMetric', iou_metrics=['mIoU', 'mDice', 'mFscore'])
test_evaluator = val_evaluator
109 changes: 109 additions & 0 deletions configs/ddrnet/ohem-DAPPM-cbam-lovasz-auxhead.py
@@ -0,0 +1,109 @@
_base_ = [
'../_base_/datasets/feces.py',
'../_base_/default_runtime.py',
]

class_weight = [0.7, 0.8, 1.1, 1.2]

checkpoint = '/home/panjm/hepengguang/mmlab_he/mmsegmentation-dev-1.x/checkpoints/ddrnet23-in1kpre_3rdparty-9ca29f62.pth' # noqa
crop_size = (224, 224)
data_preprocessor = dict(
type='SegDataPreProcessor',
size=crop_size,
# mean=[123.675, 116.28, 103.53],
# std=[58.395, 57.12, 57.375],
mean=[0.609, 0.604, 0.578],
std=[0.195, 0.192, 0.202],
bgr_to_rgb=True,
pad_val=0,
seg_pad_val=255)
norm_cfg = dict(type='SyncBN', requires_grad=True)
model = dict(
type='EncoderDecoder',
data_preprocessor=data_preprocessor,
backbone=dict(
type='DDRNet_cbam',
in_channels=3,
channels=64,
ppm_channels=128,
norm_cfg=norm_cfg,
align_corners=False,
init_cfg=None),
# init_cfg=dict(type='Pretrained', checkpoint=checkpoint)),
decode_head=dict(
type='DDRHead',
in_channels=64 * 4,
channels=128,
dropout_ratio=0.,
num_classes=4,
align_corners=False,
norm_cfg=norm_cfg,
loss_decode=[
dict(
type='LovaszLoss', class_weight=class_weight, loss_weight=1.0),
dict(
type='OhemCrossEntropy',
thres=0.9,
min_kept=131072,
class_weight=class_weight,
loss_weight=0.4),
]),
auxiliary_head=dict(
type='DDRHead',
in_channels=64 * 4,
channels=128,
dropout_ratio=0.,
num_classes=4,
align_corners=False,
norm_cfg=norm_cfg,
loss_decode=[
dict(
type='LovaszLoss', class_weight=class_weight, loss_weight=1.0),
dict(
type='OhemCrossEntropy',
thres=0.9,
min_kept=131072,
class_weight=class_weight,
loss_weight=0.4),
]),

# model training and testing settings
train_cfg=dict(),
test_cfg=dict(mode='whole'))

# train_dataloader = dict(batch_size=6, num_workers=4)

iters = 6000
# optimizer
optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0005)
optim_wrapper = dict(type='OptimWrapper', optimizer=optimizer, clip_grad=None)
# learning policy
param_scheduler = [
dict(
type='PolyLR',
eta_min=0.0001,
power=0.9,
begin=0,
end=iters,
by_epoch=False)
]

# training schedule for 120k
train_cfg = dict(type='IterBasedTrainLoop', max_iters=iters, val_interval=100)
val_cfg = dict(type='ValLoop')
test_cfg = dict(type='TestLoop')
default_hooks = dict(
timer=dict(type='IterTimerHook'),
logger=dict(type='LoggerHook', interval=5, log_metric_by_epoch=False),
param_scheduler=dict(type='ParamSchedulerHook'),
checkpoint=dict(
# type='CheckpointHook', by_epoch=False, interval=100, max_keep_ckpts=2, save_best='mIoU'),
type='CheckpointHook',
by_epoch=False,
interval=100,
max_keep_ckpts=2,
save_best='mDice'),
sampler_seed=dict(type='DistSamplerSeedHook'),
visualization=dict(type='SegVisualizationHook'))

randomness = dict(seed=304)
93 changes: 93 additions & 0 deletions configs/ddrnet/ohem-DAPPM-cbam-lovasz.py
@@ -0,0 +1,93 @@
_base_ = [
'../_base_/datasets/feces.py',
'../_base_/default_runtime.py',
]

class_weight = [0.7, 0.8, 1.1, 1.2]

checkpoint = '/home/panjm/hepengguang/mmlab_he/mmsegmentation-dev-1.x/checkpoints/ddrnet23-in1kpre_3rdparty-9ca29f62.pth' # noqa
crop_size = (224, 224)
data_preprocessor = dict(
type='SegDataPreProcessor',
size=crop_size,
mean=[0.609, 0.604, 0.578],
std=[0.195, 0.192, 0.202],
bgr_to_rgb=True,
pad_val=0,
seg_pad_val=255)
norm_cfg = dict(type='SyncBN', requires_grad=True)
model = dict(
type='EncoderDecoder',
data_preprocessor=data_preprocessor,
backbone=dict(
type='DDRNet_cbam',
in_channels=3,
channels=64,
ppm_channels=128,
norm_cfg=norm_cfg,
align_corners=False,
init_cfg=None),
# init_cfg=dict(type='Pretrained', checkpoint=checkpoint)),
decode_head=dict(
type='DDRHead',
in_channels=64 * 4,
channels=128,
dropout_ratio=0.,
num_classes=4,
align_corners=False,
norm_cfg=norm_cfg,
loss_decode=[
dict(
type='LovaszLoss',
# thres=0.9,
# min_kept=131072,
class_weight=class_weight,
loss_weight=1.0),
dict(
type='OhemCrossEntropy',
thres=0.9,
min_kept=131072,
class_weight=class_weight,
loss_weight=0.4),
]),

# model training and testing settings
train_cfg=dict(),
test_cfg=dict(mode='whole'))

# train_dataloader = dict(batch_size=6, num_workers=4)

iters = 6000
# optimizer
optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0005)
optim_wrapper = dict(type='OptimWrapper', optimizer=optimizer, clip_grad=None)
# learning policy
param_scheduler = [
dict(
type='PolyLR',
eta_min=0.0001,
power=0.9,
begin=0,
end=iters,
by_epoch=False)
]

# training schedule for 120k
train_cfg = dict(type='IterBasedTrainLoop', max_iters=iters, val_interval=100)
val_cfg = dict(type='ValLoop')
test_cfg = dict(type='TestLoop')
default_hooks = dict(
timer=dict(type='IterTimerHook'),
logger=dict(type='LoggerHook', interval=5, log_metric_by_epoch=False),
param_scheduler=dict(type='ParamSchedulerHook'),
checkpoint=dict(
# type='CheckpointHook', by_epoch=False, interval=100, max_keep_ckpts=2, save_best='mIoU'),
type='CheckpointHook',
by_epoch=False,
interval=100,
max_keep_ckpts=2,
save_best='mDice'),
sampler_seed=dict(type='DistSamplerSeedHook'),
visualization=dict(type='SegVisualizationHook'))

randomness = dict(seed=304)