Update datasets.py
Browse files- utils/datasets.py +13 -18
utils/datasets.py
CHANGED
@@ -261,10 +261,6 @@ class LoadImagesAndLabels(Dataset): # for training/testing
|
|
261 |
try:
|
262 |
path = str(Path(path)) # os-agnostic
|
263 |
parent = str(Path(path).parent) + os.sep
|
264 |
-
|
265 |
-
joined_path = os.path.join(os.getcwd(), parent)
|
266 |
-
print('Parent folder override for loading image files: %s' % (os.path.abspath(joined_path)))
|
267 |
-
|
268 |
if os.path.isfile(path): # file
|
269 |
with open(path, 'r') as f:
|
270 |
f = f.read().splitlines()
|
@@ -278,10 +274,7 @@ class LoadImagesAndLabels(Dataset): # for training/testing
|
|
278 |
raise Exception('Error loading data from %s. See %s' % (path, help_url))
|
279 |
|
280 |
n = len(self.img_files)
|
281 |
-
print('Loaded %g images' % (n))
|
282 |
assert n > 0, 'No images found in %s. See %s' % (path, help_url)
|
283 |
-
|
284 |
-
|
285 |
bi = np.floor(np.arange(n) / batch_size).astype(np.int) # batch index
|
286 |
nb = bi[-1] + 1 # number of batches
|
287 |
|
@@ -298,20 +291,22 @@ class LoadImagesAndLabels(Dataset): # for training/testing
|
|
298 |
self.label_files = [x.replace('images', 'labels').replace(os.path.splitext(x)[-1], '.txt')
|
299 |
for x in self.img_files]
|
300 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
# Rectangular Training https://github.com/ultralytics/yolov3/issues/232
|
302 |
if self.rect:
|
303 |
-
# Read image shapes (wh)
|
304 |
-
sp = path.replace('.txt', '') + '.shapes' # shapefile path
|
305 |
-
try:
|
306 |
-
with open(sp, 'r') as f: # read existing shapefile
|
307 |
-
s = [x.split() for x in f.read().splitlines()]
|
308 |
-
assert len(s) == n, 'Shapefile out of sync'
|
309 |
-
except:
|
310 |
-
s = [exif_size(Image.open(f)) for f in tqdm(self.img_files, desc='Reading image shapes')]
|
311 |
-
np.savetxt(sp, s, fmt='%g') # overwrites existing (if any)
|
312 |
-
|
313 |
# Sort by aspect ratio
|
314 |
-
s =
|
315 |
ar = s[:, 1] / s[:, 0] # aspect ratio
|
316 |
irect = ar.argsort()
|
317 |
self.img_files = [self.img_files[i] for i in irect]
|
|
|
261 |
try:
|
262 |
path = str(Path(path)) # os-agnostic
|
263 |
parent = str(Path(path).parent) + os.sep
|
|
|
|
|
|
|
|
|
264 |
if os.path.isfile(path): # file
|
265 |
with open(path, 'r') as f:
|
266 |
f = f.read().splitlines()
|
|
|
274 |
raise Exception('Error loading data from %s. See %s' % (path, help_url))
|
275 |
|
276 |
n = len(self.img_files)
|
|
|
277 |
assert n > 0, 'No images found in %s. See %s' % (path, help_url)
|
|
|
|
|
278 |
bi = np.floor(np.arange(n) / batch_size).astype(np.int) # batch index
|
279 |
nb = bi[-1] + 1 # number of batches
|
280 |
|
|
|
291 |
self.label_files = [x.replace('images', 'labels').replace(os.path.splitext(x)[-1], '.txt')
|
292 |
for x in self.img_files]
|
293 |
|
294 |
+
# Read image shapes (wh)
|
295 |
+
sp = path.replace('.txt', '') + '.shapes' # shapefile path
|
296 |
+
try:
|
297 |
+
with open(sp, 'r') as f: # read existing shapefile
|
298 |
+
s = [x.split() for x in f.read().splitlines()]
|
299 |
+
assert len(s) == n, 'Shapefile out of sync'
|
300 |
+
except:
|
301 |
+
s = [exif_size(Image.open(f)) for f in tqdm(self.img_files, desc='Reading image shapes')]
|
302 |
+
np.savetxt(sp, s, fmt='%g') # overwrites existing (if any)
|
303 |
+
|
304 |
+
self.shapes = np.array(s, dtype=np.float64)
|
305 |
+
|
306 |
# Rectangular Training https://github.com/ultralytics/yolov3/issues/232
|
307 |
if self.rect:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
# Sort by aspect ratio
|
309 |
+
s = self.shapes # wh
|
310 |
ar = s[:, 1] / s[:, 0] # aspect ratio
|
311 |
irect = ar.argsort()
|
312 |
self.img_files = [self.img_files[i] for i in irect]
|