From a7c3c86e0f172c72c04e5db643a83c32212274d5 Mon Sep 17 00:00:00 2001 From: Peterande <1043720041@qq.com> Date: Fri, 25 Oct 2024 13:16:58 +0800 Subject: [PATCH] #7 Added configs for tuning on custom dataset --- README.md | 7 +- README_cn.md | 7 +- .../objects365/dfine_hgnetv2_l_obj2custom.yml | 52 +++++++++++++++ .../objects365/dfine_hgnetv2_m_obj2custom.yml | 65 ++++++++++++++++++ .../objects365/dfine_hgnetv2_s_obj2custom.yml | 66 +++++++++++++++++++ .../objects365/dfine_hgnetv2_x_obj2custom.yml | 61 +++++++++++++++++ 6 files changed, 256 insertions(+), 2 deletions(-) create mode 100644 configs/dfine/custom/objects365/dfine_hgnetv2_l_obj2custom.yml create mode 100644 configs/dfine/custom/objects365/dfine_hgnetv2_m_obj2custom.yml create mode 100644 configs/dfine/custom/objects365/dfine_hgnetv2_s_obj2custom.yml create mode 100644 configs/dfine/custom/objects365/dfine_hgnetv2_x_obj2custom.yml diff --git a/README.md b/README.md index 2771d8c..edd29d4 100644 --- a/README.md +++ b/README.md @@ -397,7 +397,12 @@ CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --master_port=7777 --nproc_per_node=4 trai CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --master_port=7777 --nproc_per_node=4 train.py -c configs/dfine/custom/dfine_hgnetv2_${model}_custom.yml --test-only -r model.pth ``` -4. [Optional] Modify Class Mappings: +4. Tuning on Custom Dataset +```shell +CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --master_port=7777 --nproc_per_node=4 train.py -c configs/dfine/custom/dfine_hgnetv2_${model}_obj2custom.yml --use-amp --seed=0 -t model.pth +``` + +5. [Optional] Modify Class Mappings: When using the Objects365 pre-trained weights to train on your custom dataset, the example assumes that your dataset only contains the classes `'Person'` and `'Car'`. For faster convergence, you can modify `self.obj365_ids` in `src/solver/_solver.py` as follows: diff --git a/README_cn.md b/README_cn.md index 3cabf59..db71575 100644 --- a/README_cn.md +++ b/README_cn.md @@ -392,7 +392,12 @@ CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --master_port=7777 --nproc_per_node=4 trai CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --master_port=7777 --nproc_per_node=4 train.py -c configs/dfine/custom/dfine_hgnetv2_${model}_custom.yml --test-only -r model.pth ``` -4. [可选] 修改类映射: +4. 在自定义数据集上微调 +```shell +CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --master_port=7777 --nproc_per_node=4 train.py -c configs/dfine/custom/dfine_hgnetv2_${model}_obj2custom.yml --use-amp --seed=0 -t model.pth +``` + +5. [可选] 修改类映射: 在使用 Objects365 预训练权重训练自定义数据集时,示例中假设自定义数据集仅有 `'Person'` 和 `'Car'` 类,您可以将其替换为数据集中对应的任何类别。为了加快收敛,可以在 `src/solver/_solver.py` 中修改 `self.obj365_ids`,如下所示: diff --git a/configs/dfine/custom/objects365/dfine_hgnetv2_l_obj2custom.yml b/configs/dfine/custom/objects365/dfine_hgnetv2_l_obj2custom.yml new file mode 100644 index 0000000..00c5c1b --- /dev/null +++ b/configs/dfine/custom/objects365/dfine_hgnetv2_l_obj2custom.yml @@ -0,0 +1,52 @@ +__include__: [ + '../../dataset/custom_detection.yml', + '../../runtime.yml', + '../include/dataloader.yml', + '../include/optimizer.yml', + '../include/dfine_hgnetv2.yml', +] + +output_dir: ./output/dfine_hgnetv2_l_obj2custom + + +DFINE: + backbone: HGNetv2 + +HGNetv2: + name: 'B4' + return_idx: [1, 2, 3] + freeze_stem_only: True + freeze_at: 0 + freeze_norm: True + +optimizer: + type: AdamW + params: + - + params: '^(?=.*backbone)(?!.*norm|bn).*$' + lr: 0.0000125 + - + params: '^(?=.*(?:encoder|decoder))(?=.*(?:norm|bn)).*$' + weight_decay: 0. + + lr: 0.00025 + betas: [0.9, 0.999] + weight_decay: 0.000125 + + +epoches: 36 # Early stop +train_dataloader: + dataset: + transforms: + policy: + epoch: 30 + collate_fn: + stop_epoch: 30 + ema_restart_decay: 0.9999 + scale_ori_repeat: 4 + +ema: + warmups: 0 + +lr_warmup_scheduler: + warmup_duration: 0 \ No newline at end of file diff --git a/configs/dfine/custom/objects365/dfine_hgnetv2_m_obj2custom.yml b/configs/dfine/custom/objects365/dfine_hgnetv2_m_obj2custom.yml new file mode 100644 index 0000000..4fdb297 --- /dev/null +++ b/configs/dfine/custom/objects365/dfine_hgnetv2_m_obj2custom.yml @@ -0,0 +1,65 @@ +__include__: [ + '../../dataset/custom_detection.yml', + '../../runtime.yml', + '../include/dataloader.yml', + '../include/optimizer.yml', + '../include/dfine_hgnetv2.yml', +] + +output_dir: ./output/dfine_hgnetv2_m_obj2custom + + +DFINE: + backbone: HGNetv2 + +HGNetv2: + name: 'B2' + return_idx: [1, 2, 3] + freeze_at: -1 + freeze_norm: False + use_lab: True + +DFINETransformer: + num_layers: 4 # 5 6 + eval_idx: -1 # -2 -3 + +HybridEncoder: + in_channels: [384, 768, 1536] + hidden_dim: 256 + depth_mult: 0.67 + +optimizer: + type: AdamW + params: + - + params: '^(?=.*backbone)(?!.*norm|bn).*$' + lr: 0.000025 + - + params: '^(?=.*backbone)(?=.*norm|bn).*$' + lr: 0.000025 + weight_decay: 0. + - + params: '^(?=.*(?:encoder|decoder))(?=.*(?:norm|bn|bias)).*$' + weight_decay: 0. + + lr: 0.00025 + betas: [0.9, 0.999] + weight_decay: 0.000125 + + +epoches: 56 # Early stop +train_dataloader: + dataset: + transforms: + policy: + epoch: 48 + collate_fn: + stop_epoch: 48 + ema_restart_decay: 0.9999 + scale_ori_repeat: 6 + +ema: + warmups: 0 + +lr_warmup_scheduler: + warmup_duration: 0 \ No newline at end of file diff --git a/configs/dfine/custom/objects365/dfine_hgnetv2_s_obj2custom.yml b/configs/dfine/custom/objects365/dfine_hgnetv2_s_obj2custom.yml new file mode 100644 index 0000000..538cf34 --- /dev/null +++ b/configs/dfine/custom/objects365/dfine_hgnetv2_s_obj2custom.yml @@ -0,0 +1,66 @@ +__include__: [ + '../../dataset/custom_detection.yml', + '../../runtime.yml', + '../include/dataloader.yml', + '../include/optimizer.yml', + '../include/dfine_hgnetv2.yml', +] + +output_dir: ./output/dfine_hgnetv2_s_obj2custom + + +DFINE: + backbone: HGNetv2 + +HGNetv2: + name: 'B0' + return_idx: [1, 2, 3] + freeze_at: -1 + freeze_norm: False + use_lab: True + +DFINETransformer: + num_layers: 3 # 4 5 6 + eval_idx: -1 # -2 -3 -4 + +HybridEncoder: + in_channels: [256, 512, 1024] + hidden_dim: 256 + depth_mult: 0.34 + expansion: 0.5 + +optimizer: + type: AdamW + params: + - + params: '^(?=.*backbone)(?!.*norm|bn).*$' + lr: 0.000125 + - + params: '^(?=.*backbone)(?=.*norm|bn).*$' + lr: 0.000125 + weight_decay: 0. + - + params: '^(?=.*(?:encoder|decoder))(?=.*(?:norm|bn|bias)).*$' + weight_decay: 0. + + lr: 0.00025 + betas: [0.9, 0.999] + weight_decay: 0.000125 + + +epoches: 64 # Early stop +train_dataloader: + dataset: + transforms: + policy: + epoch: 56 + collate_fn: + stop_epoch: 56 + ema_restart_decay: 0.9999 + scale_ori_repeat: 10 + +ema: + warmups: 0 + +lr_warmup_scheduler: + warmup_duration: 0 \ No newline at end of file diff --git a/configs/dfine/custom/objects365/dfine_hgnetv2_x_obj2custom.yml b/configs/dfine/custom/objects365/dfine_hgnetv2_x_obj2custom.yml new file mode 100644 index 0000000..44c0501 --- /dev/null +++ b/configs/dfine/custom/objects365/dfine_hgnetv2_x_obj2custom.yml @@ -0,0 +1,61 @@ +__include__: [ + '../../dataset/custom_detection.yml', + '../../runtime.yml', + '../include/dataloader.yml', + '../include/optimizer.yml', + '../include/dfine_hgnetv2.yml', +] + +output_dir: ./output/dfine_hgnetv2_x_obj2custom + + +DFINE: + backbone: HGNetv2 + +HGNetv2: + name: 'B5' + return_idx: [1, 2, 3] + freeze_stem_only: True + freeze_at: 0 + freeze_norm: True + +HybridEncoder: + # intra + hidden_dim: 384 + dim_feedforward: 2048 + +DFINETransformer: + feat_channels: [384, 384, 384] + reg_scale: 8 + +optimizer: + type: AdamW + params: + - + params: '^(?=.*backbone)(?!.*norm|bn).*$' + lr: 0.0000025 + - + params: '^(?=.*(?:encoder|decoder))(?=.*(?:norm|bn)).*$' + weight_decay: 0. + + lr: 0.00025 + betas: [0.9, 0.999] + weight_decay: 0.000125 + + +epoches: 36 # Early stop +train_dataloader: + dataset: + transforms: + policy: + epoch: 30 + collate_fn: + stop_epoch: 30 + ema_restart_decay: 0.9999 + scale_ori_repeat: 3 + +ema: + warmups: 0 + +lr_warmup_scheduler: + warmup_duration: 0 \ No newline at end of file