Skip to content

Commit 22dc5f1

Browse files
Merge pull request #307 from mcity/roboflowmodels
Added Roboflow's RFDETR models to the Auto Labeling Workflow
2 parents de69442 + 680b0b6 commit 22dc5f1

4 files changed

Lines changed: 723 additions & 6 deletions

File tree

config/config.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import psutil
33

44
#: Select workflow list from 'WORKFLOWS = {...}' dictionary
5-
SELECTED_WORKFLOW = ["data_ingest"] # Choose from WORKFLOWS keys
5+
SELECTED_WORKFLOW = ["auto_labeling"] # Choose from WORKFLOWS keys
66

77
#: Select dataset from config/datasets.yaml
88
SELECTED_DATASET = {
@@ -66,8 +66,9 @@
6666
"mode": ["train","inference"], # "train" and "inference" supported
6767
"model_source": [
6868
# "hf_models_objectdetection",
69-
"ultralytics",
69+
#"ultralytics",
7070
# "custom_codetr",
71+
"roboflow",
7172
],
7273
"n_worker_dataloader": 8,
7374
"epochs": 1,
@@ -129,6 +130,24 @@
129130
"n_gpus": "1",
130131
"container_tool": "docker",
131132
},
133+
"roboflow": { # Roboflow RF-DETR configuration
134+
"export_dataset_root": "output/datasets/roboflow_data/",
135+
"configs": [
136+
"rfdetr_nano",
137+
"rfdetr_small",
138+
#"rfdetr_medium",
139+
#"rfdetr_large",
140+
],
141+
# RF-DETR specific parameters only
142+
"batch_size": 4, # Override default batch size
143+
"grad_accum_steps": 4, # Gradient accumulation steps
144+
"lr_encoder": None, # Encoder-specific learning rate (optional)
145+
"resolution": None, # Image resolution, must be divisible by 56 (optional)
146+
"use_ema": True, # Exponential moving average
147+
"gradient_checkpointing": False, # Memory optimization
148+
"early_stopping_min_delta": 0.001, # Minimum improvement for early stopping
149+
"early_stopping_use_ema": True, # Use EMA model for early stopping
150+
},
132151
"ultralytics": {
133152
"export_dataset_root": "output/datasets/ultralytics_data/",
134153
"multi_scale": False,

main.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from workflows.anomaly_detection import Anodec
3838
from workflows.auto_labeling import (
3939
CustomCoDETRObjectDetection,
40+
CustomRFDETRObjectDetection,
4041
HuggingFaceObjectDetection,
4142
UltralyticsObjectDetection,
4243
ZeroShotObjectDetection,
@@ -686,6 +687,7 @@ def execute(self) -> bool:
686687
"hf_models_objectdetection",
687688
"ultralytics",
688689
"custom_codetr",
690+
"roboflow",
689691
]
690692

691693
# Common parameters between models
@@ -832,6 +834,79 @@ def execute(self) -> bool:
832834
self.dataset, self.dataset_info, run_config
833835
)
834836

837+
if SUPPORTED_MODEL_SOURCES[3] in selected_model_source:
838+
839+
config_rfdetr = config_autolabel["roboflow"]
840+
841+
# Shared config parameters
842+
shared_config = {
843+
"epochs": config_autolabel["epochs"],
844+
"learning_rate": config_autolabel["learning_rate"],
845+
"weight_decay": config_autolabel["weight_decay"],
846+
"early_stop_patience": config_autolabel["early_stop_patience"],
847+
"early_stop_threshold": config_autolabel["early_stop_threshold"],
848+
}
849+
850+
run_config = {
851+
"export_dataset_root": config_rfdetr["export_dataset_root"],
852+
"mode": config_autolabel["mode"],
853+
"inference_settings": config_autolabel["inference_settings"],
854+
"config": None,
855+
# RF-DETR specific parameters
856+
"batch_size": config_rfdetr["batch_size"],
857+
"grad_accum_steps": config_rfdetr["grad_accum_steps"],
858+
"lr_encoder": config_rfdetr["lr_encoder"],
859+
"resolution": config_rfdetr["resolution"],
860+
"use_ema": config_rfdetr["use_ema"],
861+
"gradient_checkpointing": config_rfdetr["gradient_checkpointing"],
862+
"early_stopping_min_delta": config_rfdetr["early_stopping_min_delta"],
863+
"early_stopping_use_ema": config_rfdetr["early_stopping_use_ema"],
864+
}
865+
866+
rfdetr_configs = config_rfdetr["configs"]
867+
868+
for config in (
869+
pbar := tqdm(rfdetr_configs, desc="Processing RF-DETR configurations")
870+
):
871+
pbar.set_description(f"RF-DETR model {config}")
872+
run_config["config"] = config
873+
874+
try:
875+
wandb_exit_code = 0
876+
wandb_run = wandb_init(
877+
run_name=config,
878+
project_name="RF-DETR Auto Labeling",
879+
dataset_name=self.dataset_info["name"],
880+
config=run_config,
881+
wandb_activate=True,
882+
)
883+
884+
detector = CustomRFDETRObjectDetection(
885+
self.dataset, self.dataset_info, run_config
886+
)
887+
888+
# Convert data to RF-DETR format
889+
detector.convert_data()
890+
891+
# Training
892+
if "train" in mode:
893+
logging.info(f"Training RF-DETR model: {config}")
894+
detector.train(run_config, shared_config)
895+
896+
# Inference
897+
if "inference" in mode:
898+
logging.info(f"Running inference for RF-DETR model: {config}")
899+
detector.inference(
900+
inference_settings=config_autolabel["inference_settings"]
901+
)
902+
903+
except Exception as e:
904+
logging.error(f"Error during RF-DETR workflow with {config}: {e}")
905+
wandb_exit_code = 1
906+
finally:
907+
wandb_close(wandb_exit_code)
908+
909+
835910
elif workflow == "auto_labeling_zero_shot":
836911
config = WORKFLOWS["auto_labeling_zero_shot"]
837912
workflow_zero_shot_object_detection(

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ requirements-parser==0.11.0
324324
retrying==1.3.4
325325
rfc3339-validator==0.1.4
326326
rfc3986-validator==0.1.1
327+
rfdetr==1.3.0
327328
rich==13.9.1
328329
rich-argparse==1.5.2
329330
rpds-py==0.20.0

0 commit comments

Comments
 (0)