Skip to content

[WIP] Add Mask2Former swin-b swin-l config files for instance segmentation #8491

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

Open
wants to merge 5 commits into
base: dev
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: 'Close stale issues and PRs'

on:
schedule:
# check issue and pull request once every day
- cron: '25 11 * * *'

jobs:
invalid-stale-close:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v4
with:
stale-issue-message: 'This issue is marked as stale because it has been marked as invalid or awaiting response for 7 days without any further response. It will be closed in 5 days if the stale label is not removed or if there is no further response.'
stale-pr-message: 'This PR is marked as stale because there has been no activity in the past 45 days. It will be closed in 10 days if the stale label is not removed or if there is no further updates.'
close-issue-message: 'This issue is closed because it has been stale for 5 days. Please open a new issue if you have similar issues or you have any new updates now.'
close-pr-message: 'This PR is closed because it has been stale for 10 days. Please reopen this PR if you have any updates and want to keep contributing the code.'
# only issues/PRS with any of invalid and awaiting response labels are checked
any-of-labels: 'invalid, awaiting response'
days-before-issue-stale: 7
days-before-pr-stale: 45
days-before-issue-close: 5
days-before-pr-close: 10
# automatically remove the stale label when the issues or the pull reqquests are updated or commented
remove-stale-when-updated: true
2 changes: 1 addition & 1 deletion configs/htc/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# HTC

> [Hybrid Task Cascade for Instance Segmentation](ttps://arxiv.org/abs/1901.07518)
> [Hybrid Task Cascade for Instance Segmentation](https://arxiv.org/abs/1901.07518)
<!-- [ALGORITHM] -->

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
_base_ = ['./mask2former_swin-b-p4-w12-384_lsj_8x2_50e_coco.py']
pretrained = 'https://github.com/SwinTransformer/storage/releases/download/v1.0.0/swin_base_patch4_window12_384_22k.pth' # noqa

model = dict(
backbone=dict(init_cfg=dict(type='Pretrained', checkpoint=pretrained)))
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
_base_ = ['./mask2former_swin-t-p4-w7-224_lsj_8x2_50e_coco.py']
pretrained = 'https://github.com/SwinTransformer/storage/releases/download/v1.0.0/swin_base_patch4_window12_384.pth' # noqa

depths = [2, 2, 18, 2]
model = dict(
backbone=dict(
pretrain_img_size=384,
embed_dims=128,
depths=depths,
num_heads=[4, 8, 16, 32],
window_size=12,
init_cfg=dict(type='Pretrained', checkpoint=pretrained)),
panoptic_head=dict(in_channels=[128, 256, 512, 1024]))

# set all layers in backbone to lr_mult=0.1
# set all norm layers, position_embeding,
# query_embeding, level_embeding to decay_multi=0.0
backbone_norm_multi = dict(lr_mult=0.1, decay_mult=0.0)
backbone_embed_multi = dict(lr_mult=0.1, decay_mult=0.0)
embed_multi = dict(lr_mult=1.0, decay_mult=0.0)
custom_keys = {
'backbone': dict(lr_mult=0.1, decay_mult=1.0),
'backbone.patch_embed.norm': backbone_norm_multi,
'backbone.norm': backbone_norm_multi,
'absolute_pos_embed': backbone_embed_multi,
'relative_position_bias_table': backbone_embed_multi,
'query_embed': embed_multi,
'query_feat': embed_multi,
'level_embed': embed_multi
}
custom_keys.update({
f'backbone.stages.{stage_id}.blocks.{block_id}.norm': backbone_norm_multi
for stage_id, num_blocks in enumerate(depths)
for block_id in range(num_blocks)
})
custom_keys.update({
f'backbone.stages.{stage_id}.downsample.norm': backbone_norm_multi
for stage_id in range(len(depths) - 1)
})
# optimizer
optimizer = dict(
paramwise_cfg=dict(custom_keys=custom_keys, norm_decay_mult=0.0))
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
_base_ = ['./mask2former_swin-b-p4-w12-384_lsj_8x2_50e_coco.py']
pretrained = 'https://github.com/SwinTransformer/storage/releases/download/v1.0.0/swin_large_patch4_window12_384_22k.pth' # noqa

model = dict(
backbone=dict(
embed_dims=192,
num_heads=[6, 12, 24, 48],
init_cfg=dict(type='Pretrained', checkpoint=pretrained)),
panoptic_head=dict(num_queries=200, in_channels=[192, 384, 768, 1536]))

data = dict(samples_per_gpu=1, workers_per_gpu=1)

lr_config = dict(step=[655556, 710184])

max_iters = 737500
runner = dict(type='IterBasedRunner', max_iters=max_iters)

# Before 735001th iteration, we do evaluation every 5000 iterations.
# After 735000th iteration, we do evaluation every 737500 iterations,
# which means that we do evaluation at the end of training.
interval = 5000
dynamic_intervals = [(max_iters // interval * interval + 1, max_iters)]
evaluation = dict(
interval=interval,
dynamic_intervals=dynamic_intervals,
metric=['bbox', 'segm'])
1 change: 1 addition & 0 deletions requirements/docs.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
docutils==0.16.0
markdown<3.4.0
myst-parser
-e git+https://github.com/open-mmlab/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme
sphinx==4.0.2
Expand Down
20 changes: 3 additions & 17 deletions tools/deployment/pytorch2onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,31 +101,17 @@ def pytorch2onnx(model,

model.forward = origin_forward

# get the custom op path
ort_custom_op_path = ''
try:
from mmcv.ops import get_onnxruntime_op_path
ort_custom_op_path = get_onnxruntime_op_path()
except (ImportError, ModuleNotFoundError):
warnings.warn('If input model has custom op from mmcv, \
you may have to build mmcv with ONNXRuntime from source.')

if do_simplify:
import onnxsim

from mmdet import digit_version

min_required_version = '0.3.0'
min_required_version = '0.4.0'
assert digit_version(onnxsim.__version__) >= digit_version(
min_required_version
), f'Requires to install onnx-simplify>={min_required_version}'
), f'Requires to install onnxsim>={min_required_version}'

input_dic = {'input': img_list[0].detach().cpu().numpy()}
model_opt, check_ok = onnxsim.simplify(
output_file,
input_data=input_dic,
custom_lib=ort_custom_op_path,
dynamic_input_shape=dynamic_export)
model_opt, check_ok = onnxsim.simplify(output_file)
if check_ok:
onnx.save(model_opt, output_file)
print(f'Successfully simplified ONNX model: {output_file}')
Expand Down