updates
This commit is contained in:
parent
8be4b41b3d
commit
6a05cf56c2
2
test.py
2
test.py
|
@ -101,7 +101,7 @@ def test(cfg,
|
|||
# [{"image_id": 42, "category_id": 18, "bbox": [258.15, 41.29, 348.26, 243.78], "score": 0.236}, ...
|
||||
image_id = int(Path(paths[si]).stem.split('_')[-1])
|
||||
box = pred[:, :4].clone() # xyxy
|
||||
scale_coords(imgs[si].shape[1:], box, shapes[si]) # to original shape
|
||||
scale_coords(imgs[si].shape[1:], box, shapes[si][0], shapes[si][1]) # to original shape
|
||||
box = xyxy2xywh(box) # xywh
|
||||
box[:, :2] -= box[:, 2:] / 2 # xy center to top-left corner
|
||||
for di, d in enumerate(pred):
|
||||
|
|
|
@ -416,6 +416,7 @@ class LoadImagesAndLabels(Dataset): # for training/testing
|
|||
# Load mosaic
|
||||
img, labels = load_mosaic(self, index)
|
||||
h, w = img.shape[:2]
|
||||
ratio, pad = None, None
|
||||
|
||||
else:
|
||||
# Load image
|
||||
|
@ -492,14 +493,14 @@ class LoadImagesAndLabels(Dataset): # for training/testing
|
|||
img = np.ascontiguousarray(img, dtype=np.float32) # uint8 to float32
|
||||
img /= 255.0 # 0 - 255 to 0.0 - 1.0
|
||||
|
||||
return torch.from_numpy(img), labels_out, img_path, (h, w)
|
||||
return torch.from_numpy(img), labels_out, img_path, ((h, w), (ratio, pad))
|
||||
|
||||
@staticmethod
|
||||
def collate_fn(batch):
|
||||
img, label, path, hw = list(zip(*batch)) # transposed
|
||||
img, label, path, shapes = list(zip(*batch)) # transposed
|
||||
for i, l in enumerate(label):
|
||||
l[:, 0] = i # add target image index for build_targets()
|
||||
return torch.stack(img, 0), torch.cat(label, 0), path, hw
|
||||
return torch.stack(img, 0), torch.cat(label, 0), path, shapes
|
||||
|
||||
|
||||
def load_image(self, index):
|
||||
|
|
|
@ -126,7 +126,7 @@ def xywh2xyxy(x):
|
|||
|
||||
def scale_coords(img1_shape, coords, img0_shape, ratio_pad=None):
|
||||
# Rescale coords (xyxy) from img1_shape to img0_shape
|
||||
if ratio_pad is None: # not supplied, calculate
|
||||
if ratio_pad is None: # calculate from img0_shape
|
||||
gain = max(img1_shape) / max(img0_shape) # gain = old / new
|
||||
pad = (img1_shape[1] - img0_shape[1] * gain) / 2, (img1_shape[0] - img0_shape[0] * gain) / 2 # wh padding
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue