Update metrics names (#85)

This commit is contained in:
Glenn Jocher
2022-12-24 02:32:24 +01:00
committed by GitHub
parent 6432afc5f9
commit 248d54ca03
9 changed files with 30 additions and 36 deletions

View File

@ -46,6 +46,7 @@ class DetectionTrainer(BaseTrainer):
return model
def get_validator(self):
self.loss_names = 'box_loss', 'obj_loss', 'cls_loss'
return v8.detect.DetectionValidator(self.test_loader,
save_dir=self.save_dir,
logger=self.console,
@ -190,15 +191,14 @@ class DetectionTrainer(BaseTrainer):
loss = lbox + lobj + lcls
return loss * bs, torch.cat((lbox, lobj, lcls)).detach()
# TODO: improve from API users perspective
def label_loss_items(self, loss_items=None, prefix="train"):
# We should just use named tensors here in future
keys = [f"{prefix}/lbox", f"{prefix}/lobj", f"{prefix}/lcls"]
keys = [f"{prefix}/{x}" for x in self.loss_names]
return dict(zip(keys, loss_items)) if loss_items is not None else keys
def progress_string(self):
return ('\n' + '%11s' * 6) % \
('Epoch', 'GPU_mem', 'box_loss', 'obj_loss', 'cls_loss', 'Size')
('Epoch', 'GPU_mem', *self.loss_names, 'Size')
def plot_training_samples(self, batch, ni):
images = batch["img"]

View File

@ -173,7 +173,7 @@ class DetectionValidator(BaseValidator):
# TODO: align with train loss metrics
@property
def metric_keys(self):
return ["metrics/precision(B)", "metrics/recall(B)", "metrics/mAP_0.5(B)", "metrics/mAP_0.5:0.95(B)"]
return ["metrics/precision(B)", "metrics/recall(B)", "metrics/mAP50(B)", "metrics/mAP50-95(B)"]
def plot_val_samples(self, batch, ni):
images = batch["img"]

View File

@ -29,6 +29,7 @@ class SegmentationTrainer(DetectionTrainer):
return model
def get_validator(self):
self.loss_names = 'box_loss', 'seg_loss', 'obj_loss', 'cls_loss'
return v8.segment.SegmentationValidator(self.test_loader,
save_dir=self.save_dir,
logger=self.console,
@ -212,12 +213,12 @@ class SegmentationTrainer(DetectionTrainer):
def label_loss_items(self, loss_items=None, prefix="train"):
# We should just use named tensors here in future
keys = [f"{prefix}/lbox", f"{prefix}/lseg", f"{prefix}/lobj", f"{prefix}/lcls"]
keys = [f"{prefix}/{x}" for x in self.loss_names]
return dict(zip(keys, loss_items)) if loss_items is not None else keys
def progress_string(self):
return ('\n' + '%11s' * 7) % \
('Epoch', 'GPU_mem', 'box_loss', 'seg_loss', 'obj_loss', 'cls_loss', 'Size')
('Epoch', 'GPU_mem', *self.loss_names, 'Size')
def plot_training_samples(self, batch, ni):
images = batch["img"]

View File

@ -178,12 +178,12 @@ class SegmentationValidator(DetectionValidator):
return [
"metrics/precision(B)",
"metrics/recall(B)",
"metrics/mAP_0.5(B)",
"metrics/mAP_0.5:0.95(B)", # metrics
"metrics/mAP50(B)",
"metrics/mAP50-95(B)", # metrics
"metrics/precision(M)",
"metrics/recall(M)",
"metrics/mAP_0.5(M)",
"metrics/mAP_0.5:0.95(M)",]
"metrics/mAP50(M)",
"metrics/mAP50-95(M)",]
def plot_val_samples(self, batch, ni):
images = batch["img"]