Clean validator (#144)

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>
This commit is contained in:
Laughing
2023-01-05 21:14:01 +08:00
committed by GitHub
parent 46cb657b64
commit 19334ebb16
9 changed files with 88 additions and 74 deletions

View File

@ -463,6 +463,8 @@ class LetterBox:
dw /= 2 # divide padding into 2 sides
dh /= 2
if labels.get("ratio_pad"):
labels["ratio_pad"] = (labels["ratio_pad"], (dw, dh)) # for evaluation
if shape[::-1] != new_unpad: # resize
img = cv2.resize(img, new_unpad, interpolation=cv2.INTER_LINEAR)

View File

@ -179,6 +179,10 @@ class BaseDataset(Dataset):
def get_label_info(self, index):
label = self.labels[index].copy()
label["img"], label["ori_shape"], label["resized_shape"] = self.load_image(index)
label["ratio_pad"] = (
label["resized_shape"][0] / label["ori_shape"][0],
label["resized_shape"][1] / label["ori_shape"][1],
) # for evaluation
if self.rect:
label["rect_shape"] = self.batch_shapes[self.batch[index]]
label = self.update_labels_info(label)

View File

@ -895,7 +895,7 @@ class LoadImagesAndLabels(Dataset):
batch_idx, cls, bboxes = torch.cat(label, 0).split((1, 1, 4), dim=1)
return {
'ori_shape': tuple((x[0] if x else None) for x in shapes),
'resized_shape': tuple(tuple(x.shape[1:]) for x in im),
'ratio_pad': tuple((x[1] if x else None) for x in shapes),
'im_file': path,
'img': torch.stack(im, 0),
'cls': cls,

View File

@ -127,7 +127,7 @@ class YOLODataset(BaseDataset):
mosaic = self.augment and not self.rect
transforms = mosaic_transforms(self, self.imgsz, hyp) if mosaic else affine_transforms(self.imgsz, hyp)
else:
transforms = Compose([LetterBox(new_shape=(self.imgsz, self.imgsz))])
transforms = Compose([LetterBox(new_shape=(self.imgsz, self.imgsz), scaleup=False)])
transforms.append(
Format(bbox_format="xywh",
normalize=True,