Spaces:
Running
on
Zero
Running
on
Zero
Create deformable_train_voc_eval_nonvoc.py
Browse files
deformable_train_voc_eval_nonvoc.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from detrex.config import get_config
|
| 2 |
+
from ..models.dino_r50 import model
|
| 3 |
+
|
| 4 |
+
import itertools
|
| 5 |
+
|
| 6 |
+
from omegaconf import OmegaConf
|
| 7 |
+
|
| 8 |
+
from detectron2.config import LazyCall as L
|
| 9 |
+
from detectron2.data import (
|
| 10 |
+
build_detection_test_loader,
|
| 11 |
+
build_detection_train_loader,
|
| 12 |
+
get_detection_dataset_dicts,
|
| 13 |
+
)
|
| 14 |
+
from detectron2.data.datasets import register_coco_instances
|
| 15 |
+
|
| 16 |
+
from detectron2.modeling.backbone import ResNet, BasicStem
|
| 17 |
+
|
| 18 |
+
from projects.vCLR_deformable_mask.modeling import OursDatasetMapper
|
| 19 |
+
|
| 20 |
+
dataloader = OmegaConf.create()
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
# get default config
|
| 26 |
+
optimizer = get_config("common/optim.py").AdamW
|
| 27 |
+
lr_multiplier = get_config("common/coco_schedule.py").lr_multiplier_5ep
|
| 28 |
+
train = get_config("common/train.py").train
|
| 29 |
+
|
| 30 |
+
# modify training config
|
| 31 |
+
train.init_checkpoint = "detectron2://ImageNetPretrained/torchvision/R-50.pkl"
|
| 32 |
+
train.output_dir = "./output/dino_openworld"
|
| 33 |
+
|
| 34 |
+
# max training iterations
|
| 35 |
+
train.max_iter = 60000
|
| 36 |
+
train.eval_period = 5000
|
| 37 |
+
train.log_period = 200
|
| 38 |
+
train.checkpointer.period = 5000
|
| 39 |
+
|
| 40 |
+
# gradient clipping for training
|
| 41 |
+
train.clip_grad.enabled = True
|
| 42 |
+
train.clip_grad.params.max_norm = 0.1
|
| 43 |
+
train.clip_grad.params.norm_type = 2
|
| 44 |
+
|
| 45 |
+
# set training devices
|
| 46 |
+
train.device = "cuda"
|
| 47 |
+
model.device = train.device
|
| 48 |
+
|
| 49 |
+
# modify optimizer config
|
| 50 |
+
optimizer.lr = 1e-4 # original 1e-4
|
| 51 |
+
optimizer.betas = (0.9, 0.999)
|
| 52 |
+
optimizer.weight_decay = 1e-4
|
| 53 |
+
optimizer.params.lr_factor_func = lambda module_name: 0.1 if "backbone" in module_name else 1
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
# modify model config
|
| 59 |
+
model.dn_number = 100
|
| 60 |
+
model.num_classes = 1
|
| 61 |
+
model.select_box_nums_for_evaluation=900
|
| 62 |
+
|
| 63 |
+
# ema
|
| 64 |
+
train.model_ema.enabled=True
|
| 65 |
+
train.model_ema.decay=0.999
|
| 66 |
+
|
| 67 |
+
model.num_queries = 2000
|
| 68 |
+
|
| 69 |
+
model.transformer.encoder.use_checkpoint=False
|
| 70 |
+
model.transformer.decoder.use_checkpoint=False
|
| 71 |
+
|
| 72 |
+
train.model_ema.use_ema_weights_for_eval_only=True
|