Spaces:
Sleeping
Sleeping
File size: 5,446 Bytes
b34d1d6 1f8df14 b34d1d6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
from torch.nn import GroupNorm, ReLU
from mmdet.models import MSDeformAttnPixelDecoder, CrossEntropyLoss, DiceLoss, FocalLoss
from mmdet.models.task_modules.assigners import HungarianAssigner, ClassificationCost, CrossEntropyLossCost, DiceCost
from mmdet.models.task_modules.samplers import MaskPseudoSampler
from seg.models.detectors import Mask2formerVideo
from seg.models.fusion_head import OMGFusionHead
from seg.models.heads import Mask2FormerVideoHead
from seg.models.backbones import OpenCLIPBackbone
num_things_classes = 80
num_stuff_classes = 53
ov_model_name = 'convnext_large_d_320'
ov_datasets_name = 'CocoPanopticOVDataset'
model = dict(
type=Mask2formerVideo,
data_preprocessor=None, # to fill
backbone=dict(
type=OpenCLIPBackbone,
model_name='convnext_large_d_320',
fix=True,
init_cfg=dict(
type='clip_pretrain',
checkpoint='laion2b_s29b_b131k_ft_soup'
)
),
panoptic_head=dict(
init_cfg=dict(
type='Pretrained',
checkpoint='./models/omg_seg_convl.pth',
prefix='panoptic_head.'
),
type=Mask2FormerVideoHead,
sphere_cls=True,
ov_classifier_name=f'{ov_model_name}_{ov_datasets_name}',
logit=None,
enable_box_query=True,
in_channels=[192, 384, 768, 1536], # pass to pixel_decoder inside
strides=[4, 8, 16, 32],
feat_channels=256,
out_channels=256,
num_things_classes=num_things_classes,
num_stuff_classes=num_stuff_classes,
num_queries=300,
num_transformer_feat_level=3,
pixel_decoder=dict(
type=MSDeformAttnPixelDecoder,
num_outs=3,
norm_cfg=dict(type=GroupNorm, num_groups=32),
act_cfg=dict(type=ReLU),
encoder=dict( # DeformableDetrTransformerEncoder
num_layers=6,
layer_cfg=dict( # DeformableDetrTransformerEncoderLayer
self_attn_cfg=dict( # MultiScaleDeformableAttention
embed_dims=256,
num_heads=8,
num_levels=3,
num_points=4,
dropout=0.0,
batch_first=True),
ffn_cfg=dict(
embed_dims=256,
feedforward_channels=1024,
num_fcs=2,
ffn_drop=0.0,
act_cfg=dict(type=ReLU, inplace=True)))),
positional_encoding=dict(num_feats=128, normalize=True)),
enforce_decoder_input_project=False,
positional_encoding=dict(num_feats=128, normalize=True),
transformer_decoder=dict( # Mask2FormerTransformerDecoder
return_intermediate=True,
num_layers=9,
layer_cfg=dict( # Mask2FormerTransformerDecoderLayer
self_attn_cfg=dict( # MultiheadAttention
embed_dims=256,
num_heads=8,
dropout=0.0,
batch_first=True),
cross_attn_cfg=dict( # MultiheadAttention
embed_dims=256,
num_heads=8,
dropout=0.0,
batch_first=True),
ffn_cfg=dict(
embed_dims=256,
feedforward_channels=2048,
num_fcs=2,
ffn_drop=0.0,
act_cfg=dict(type='ReLU', inplace=True))),
init_cfg=None),
loss_cls=dict(
type=CrossEntropyLoss,
use_sigmoid=False,
loss_weight=2.0,
reduction='mean',
class_weight=None # [1.0] * num_classes + [0.1]
),
loss_mask=dict(
type=CrossEntropyLoss,
use_sigmoid=True,
reduction='mean',
loss_weight=5.0),
loss_dice=dict(
type=DiceLoss,
use_sigmoid=True,
activate=True,
reduction='mean',
naive_dice=True,
eps=1.0,
loss_weight=5.0),
loss_iou=dict(
type=FocalLoss,
use_sigmoid=True,
loss_weight=2.0,
reduction='mean'
)
),
panoptic_fusion_head=dict(
type=OMGFusionHead,
num_things_classes=num_things_classes,
num_stuff_classes=num_stuff_classes,
loss_panoptic=None,
init_cfg=None
),
train_cfg=dict(
num_points=12544,
oversample_ratio=3.0,
importance_sample_ratio=0.75,
assigner=dict(
type=HungarianAssigner,
match_costs=[
dict(type=ClassificationCost, weight=2.0),
dict(
type=CrossEntropyLossCost, weight=5.0, use_sigmoid=True),
dict(type=DiceCost, weight=5.0, pred_act=True, eps=1.0)
]),
sampler=dict(type=MaskPseudoSampler)),
test_cfg=dict(
panoptic_on=True,
semantic_on=False,
instance_on=True,
# max_per_image is for instance segmentation.
max_per_image=100,
iou_thr=0.8,
# In Mask2Former's panoptic postprocessing,
# it will filter mask area where score is less than 0.5 .
filter_low_score=True,
object_mask_thr=0.,
),
init_cfg=None
)
|