You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

AD_dsxw_test18.py 6.2 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. _base_ = [
  2. '../_base_/datasets/coco_detection.py', '../_base_/default_runtime.py'
  3. ]
  4. model = dict(
  5. type='DeformableDETR',
  6. backbone=dict(
  7. type='ResNet',
  8. depth=50,
  9. num_stages=4,
  10. out_indices=(1, 2, 3),
  11. frozen_stages=1,
  12. norm_cfg=dict(type='BN', requires_grad=False),
  13. norm_eval=True,
  14. style='pytorch',
  15. init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50')),
  16. neck=dict(
  17. type='ChannelMapper',
  18. in_channels=[512, 1024, 2048],
  19. kernel_size=1,
  20. out_channels=256,
  21. act_cfg=None,
  22. norm_cfg=dict(type='GN', num_groups=32),
  23. num_outs=4),
  24. bbox_head=dict(
  25. type='DeformableDETRHead',
  26. with_box_refine=True,
  27. as_two_stage=True,
  28. num_query=300,
  29. num_classes=11,
  30. in_channels=2048,
  31. sync_cls_avg_factor=True,
  32. transformer=dict(
  33. type='DeformableDetrTransformer',
  34. encoder=dict(
  35. type='DetrTransformerEncoder',
  36. num_layers=6,
  37. transformerlayers=dict(
  38. type='BaseTransformerLayer',
  39. attn_cfgs=dict(
  40. type='MultiScaleDeformableAttention', embed_dims=256),
  41. feedforward_channels=1024,
  42. ffn_dropout=0.1,
  43. operation_order=('self_attn', 'norm', 'ffn', 'norm'))),
  44. decoder=dict(
  45. type='DeformableDetrTransformerDecoder',
  46. num_layers=6,
  47. return_intermediate=True,
  48. transformerlayers=dict(
  49. type='DetrTransformerDecoderLayer',
  50. attn_cfgs=[
  51. dict(
  52. type='MultiheadAttention',
  53. embed_dims=256,
  54. num_heads=8,
  55. dropout=0.1),
  56. dict(
  57. type='MultiScaleDeformableAttention',
  58. embed_dims=256)
  59. ],
  60. feedforward_channels=1024,
  61. ffn_dropout=0.1,
  62. operation_order=('self_attn', 'norm', 'cross_attn', 'norm',
  63. 'ffn', 'norm')))),
  64. positional_encoding=dict(
  65. type='SinePositionalEncoding',
  66. num_feats=128,
  67. normalize=True,
  68. offset=-0.5),
  69. loss_cls=dict(
  70. type='FocalLoss',
  71. use_sigmoid=True,
  72. gamma=2.0,
  73. alpha=0.25,
  74. loss_weight=2.0),
  75. loss_bbox=dict(type='L1Loss', loss_weight=5.0),
  76. loss_iou=dict(type='GIoULoss', loss_weight=2.0)),
  77. # training and testing settings
  78. train_cfg=dict(
  79. assigner=dict(
  80. type='HungarianAssigner',
  81. cls_cost=dict(type='FocalLossCost', weight=2.0),
  82. reg_cost=dict(type='BBoxL1Cost', weight=5.0, box_format='xywh'),
  83. iou_cost=dict(type='IoUCost', iou_mode='giou', weight=2.0))),
  84. test_cfg=dict(max_per_img=100))
  85. img_norm_cfg = dict(
  86. mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)
  87. # train_pipeline, NOTE the img_scale and the Pad's size_divisor is different
  88. # from the default setting in mmdet.
  89. train_pipeline = [
  90. dict(type='LoadImageFromFile'),
  91. dict(type='LoadAnnotations', with_bbox=True),
  92. dict(
  93. type='Resize',
  94. img_scale=[(400, 300), (500, 400)],
  95. multiscale_mode='value',
  96. keep_ratio=True),
  97. dict(type='RandomFlip', flip_ratio=[0.2,0.2,0.2], direction=['horizontal', 'vertical', 'diagonal']),
  98. dict(type='BrightnessTransform', level=5, prob=0.5),
  99. dict(type='ContrastTransform', level=5, prob=0.5),
  100. dict(type='RandomShift', shift_ratio=0.5),
  101. dict(type='MinIoURandomCrop', min_ious=(0.5, 0.7, 0.9), min_crop_size=0.8),
  102. dict(type='Normalize', **img_norm_cfg),
  103. dict(type='Pad', size_divisor=32),
  104. dict(type='DefaultFormatBundle'),
  105. dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels']),
  106. ]
  107. test_pipeline = [
  108. dict(type='LoadImageFromFile'),
  109. dict(
  110. type='MultiScaleFlipAug',
  111. img_scale=(400, 300),
  112. flip=False,
  113. transforms=[
  114. dict(type='Resize', keep_ratio=True),
  115. dict(type='RandomFlip'),
  116. dict(type='Normalize', **img_norm_cfg),
  117. dict(type='Pad', size_divisor=32),
  118. dict(type='ImageToTensor', keys=['img']),
  119. dict(type='Collect', keys=['img']),
  120. ])
  121. ]
  122. dataset_type = 'CocoDataset'
  123. classes = ('yiwei','loujian','celi','libei','fantie','lianxi','duojian','shunjian','shaoxi','jiahan','yiwu')
  124. data = dict(
  125. samples_per_gpu=16,
  126. workers_per_gpu=8,
  127. train=dict(
  128. type=dataset_type,
  129. img_prefix='/home/shanwei-luo/userdata/datasets/dsxw_dataset_v4/dsxw_train/images/',
  130. classes=classes,
  131. ann_file='/home/shanwei-luo/userdata/datasets/dsxw_dataset_v4/dsxw_train/annotations/train.json',
  132. pipeline=train_pipeline),
  133. val=dict(
  134. type=dataset_type,
  135. img_prefix='/home/shanwei-luo/userdata/datasets/dsxw_dataset_v4/dsxw_test/images/',
  136. classes=classes,
  137. ann_file='/home/shanwei-luo/userdata/datasets/dsxw_dataset_v4/dsxw_test/annotations/test.json',
  138. pipeline=test_pipeline),
  139. test=dict(
  140. type=dataset_type,
  141. img_prefix='/home/shanwei-luo/userdata/datasets/dsxw_dataset_v4/dsxw_test/images/',
  142. classes=classes,
  143. ann_file='/home/shanwei-luo/userdata/datasets/dsxw_dataset_v4/dsxw_test/annotations/test.json',
  144. pipeline=test_pipeline))
  145. # optimizer
  146. optimizer = dict(
  147. type='AdamW',
  148. lr=2e-4,
  149. weight_decay=0.0001,
  150. paramwise_cfg=dict(
  151. custom_keys={
  152. 'backbone': dict(lr_mult=0.1),
  153. 'sampling_offsets': dict(lr_mult=0.1),
  154. 'reference_points': dict(lr_mult=0.1)
  155. }))
  156. optimizer_config = dict(grad_clip=dict(max_norm=0.1, norm_type=2))
  157. # learning policy
  158. lr_config = dict(policy='step', step=[40])
  159. runner = dict(type='EpochBasedRunner', max_epochs=60)
  160. evaluation = dict(interval=5, metric='bbox')

No Description

Contributors (1)