One function drives every experiment in this article — resolution, model scale, and augmentation are just different arguments to the same call.
def run_experiment(name, model_size, imgsz, extra_kwargs=None):
model = YOLO(f'yolo12{model_size}.pt')
kwargs = dict(
data=VISDRONE_YAML,
imgsz=imgsz,
batch=16 if imgsz == 320 else 8,
epochs=150,
patience=20,
project=PROJECT_DIR,
name=name,
)
if extra_kwargs:
kwargs.update(extra_kwargs)
model.train(**kwargs)
metrics = model.val(data=VISDRONE_YAML, imgsz=imgsz, verbose=False)
return float(metrics.box.map50), float(metrics.box.map), float(metrics.box.mr)
# Resolution comparison — same function, different imgsz
run_experiment('yolo12n_320', model_size='n', imgsz=320)
run_experiment('yolo12n_640', model_size='n', imgsz=640)