Release 8.0.5 PR (#279)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: Izam Mohammed <106471909+izam-mohammed@users.noreply.github.com> Co-authored-by: Yue WANG 王跃 <92371174+yuewangg@users.noreply.github.com> Co-authored-by: Thibaut Lucas <thibautlucas13@gmail.com>
This commit is contained in:
@ -24,7 +24,7 @@ class DetectionValidator(BaseValidator):
|
||||
self.data_dict = yaml_load(check_file(self.args.data), append_filename=True) if self.args.data else None
|
||||
self.is_coco = False
|
||||
self.class_map = None
|
||||
self.metrics = DetMetrics(save_dir=self.save_dir, plot=self.args.plots)
|
||||
self.metrics = DetMetrics(save_dir=self.save_dir)
|
||||
self.iouv = torch.linspace(0.5, 0.95, 10) # iou vector for mAP@0.5:0.95
|
||||
self.niou = self.iouv.numel()
|
||||
|
||||
@ -34,8 +34,7 @@ class DetectionValidator(BaseValidator):
|
||||
for k in ["batch_idx", "cls", "bboxes"]:
|
||||
batch[k] = batch[k].to(self.device)
|
||||
|
||||
nb, _, height, width = batch["img"].shape
|
||||
batch["bboxes"] *= torch.tensor((width, height, width, height), device=self.device) # to pixels
|
||||
nb = len(batch["img"])
|
||||
self.lb = [torch.cat([batch["cls"], batch["bboxes"]], dim=-1)[batch["batch_idx"] == i]
|
||||
for i in range(nb)] if self.args.save_hybrid else [] # for autolabelling
|
||||
|
||||
@ -50,6 +49,7 @@ class DetectionValidator(BaseValidator):
|
||||
self.nc = head.nc
|
||||
self.names = model.names
|
||||
self.metrics.names = self.names
|
||||
self.metrics.plot = self.args.plots
|
||||
self.confusion_matrix = ConfusionMatrix(nc=self.nc)
|
||||
self.seen = 0
|
||||
self.jdict = []
|
||||
@ -95,7 +95,9 @@ class DetectionValidator(BaseValidator):
|
||||
|
||||
# Evaluate
|
||||
if nl:
|
||||
tbox = ops.xywh2xyxy(bbox) # target boxes
|
||||
height, width = batch["img"].shape[2:]
|
||||
tbox = ops.xywh2xyxy(bbox) * torch.tensor(
|
||||
(width, height, width, height), device=self.device) # target boxes
|
||||
ops.scale_boxes(batch["img"][si].shape[1:], tbox, shape,
|
||||
ratio_pad=batch["ratio_pad"][si]) # native-space labels
|
||||
labelsn = torch.cat((cls, tbox), 1) # native-space labels
|
||||
|
@ -22,7 +22,7 @@ class SegmentationValidator(DetectionValidator):
|
||||
def __init__(self, dataloader=None, save_dir=None, pbar=None, logger=None, args=None):
|
||||
super().__init__(dataloader, save_dir, pbar, logger, args)
|
||||
self.args.task = "segment"
|
||||
self.metrics = SegmentMetrics(save_dir=self.save_dir, plot=self.args.plots)
|
||||
self.metrics = SegmentMetrics(save_dir=self.save_dir)
|
||||
|
||||
def preprocess(self, batch):
|
||||
batch = super().preprocess(batch)
|
||||
@ -31,13 +31,15 @@ class SegmentationValidator(DetectionValidator):
|
||||
|
||||
def init_metrics(self, model):
|
||||
head = model.model[-1] if self.training else model.model.model[-1]
|
||||
self.is_coco = self.data.get('val', '').endswith(f'coco{os.sep}val2017.txt') # is COCO dataset
|
||||
val = self.data.get('val', '') # validation path
|
||||
self.is_coco = isinstance(val, str) and val.endswith(f'coco{os.sep}val2017.txt') # is COCO dataset
|
||||
self.class_map = ops.coco80_to_coco91_class() if self.is_coco else list(range(1000))
|
||||
self.args.save_json |= self.is_coco and not self.training # run on final val if training COCO
|
||||
self.nc = head.nc
|
||||
self.nm = head.nm if hasattr(head, "nm") else 32
|
||||
self.names = model.names
|
||||
self.metrics.names = self.names
|
||||
self.metrics.plot = self.args.plots
|
||||
self.confusion_matrix = ConfusionMatrix(nc=self.nc)
|
||||
self.plot_masks = []
|
||||
self.seen = 0
|
||||
@ -97,7 +99,9 @@ class SegmentationValidator(DetectionValidator):
|
||||
|
||||
# Evaluate
|
||||
if nl:
|
||||
tbox = ops.xywh2xyxy(bbox) # target boxes
|
||||
height, width = batch["img"].shape[2:]
|
||||
tbox = ops.xywh2xyxy(bbox) * torch.tensor(
|
||||
(width, height, width, height), device=self.device) # target boxes
|
||||
ops.scale_boxes(batch["img"][si].shape[1:], tbox, shape,
|
||||
ratio_pad=batch["ratio_pad"][si]) # native-space labels
|
||||
labelsn = torch.cat((cls, tbox), 1) # native-space labels
|
||||
|
Reference in New Issue
Block a user