This commit is contained in:
Glenn Jocher
2019-11-30 18:45:43 -08:00
parent 8be4b41b3d
commit 6a05cf56c2
3 changed files with 6 additions and 5 deletions
+4 -3
View File
@@ -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):
+1 -1
View File
@@ -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: