This commit is contained in:
Glenn Jocher 2019-05-05 14:13:05 +02:00
parent a8f443518f
commit 4156e83319
4 changed files with 122276 additions and 4 deletions

4
.gitignore vendored
View File

@ -26,6 +26,10 @@ data/*
!data/coco.data
!data/coco_*.data
!data/coco_*.txt
!data/coco_*.txt
!data/trainvalno5k.shapes
!data/5k.shapes
pycocotools/*
results*.txt

5000
data/5k.shapes Normal file

File diff suppressed because it is too large Load Diff

117263
data/trainvalno5k.shapes Normal file

File diff suppressed because it is too large Load Diff

View File

@ -150,12 +150,17 @@ class LoadImagesAndLabels(Dataset): # for training/testing
nb = bi[-1] + 1 # number of batches
from PIL import Image
# Read image aspect ratios
iter = tqdm(self.img_files, desc='Reading image shapes') if n > 100 else self.img_files
s = np.array([Image.open(f).size for f in iter])
ar = s[:, 1] / s[:, 0] # aspect ratio
# Read image shapes
sp = 'data' + os.sep + path.replace('.txt', '.shapes').split(os.sep)[-1] # shapefile path
if os.path.exists(sp): # read existing shapefile
with open(sp, 'r') as f:
s = np.array([x.split() for x in f.read().splitlines()], dtype=np.float32)
else: # no shapefile, so read shape using PIL and write shapefile for next time (faster)
s = np.array([Image.open(f).size for f in tqdm(self.img_files, desc='Reading image shapes')])
np.savetxt(sp, s, fmt='%g')
# Sort by aspect ratio
ar = s[:, 1] / s[:, 0] # aspect ratio
i = ar.argsort()
ar = ar[i]
self.img_files = [self.img_files[i] for i in i]