Refactor collections and fstrings (#7821)
* Update torch_utils.py * Additional code refactoring * tuples to sets * Cleanup
This commit is contained in:
1 parent
3356f2609c
commit
f00071416f
9 files changed
+58
-63
No files matched your search
+7
-10
@@ -57,9 +57,7 @@ def exif_size(img):
|
||||
s = img.size # (width, height)
|
||||
try:
|
||||
rotation = dict(img._getexif().items())[orientation]
|
||||
if rotation == 6: # rotation 270
|
||||
s = (s[1], s[0])
|
||||
elif rotation == 8: # rotation 90
|
||||
if rotation in [6, 8]: # rotation 270 or 90
|
||||
s = (s[1], s[0])
|
||||
except Exception:
|
||||
pass
|
||||
@@ -156,7 +154,7 @@ class InfiniteDataLoader(dataloader.DataLoader):
|
||||
return len(self.batch_sampler.sampler)
|
||||
|
||||
def __iter__(self):
|
||||
for i in range(len(self)):
|
||||
for _ in range(len(self)):
|
||||
yield next(self.iterator)
|
||||
|
||||
|
||||
@@ -224,10 +222,9 @@ class LoadImages:
|
||||
self.cap.release()
|
||||
if self.count == self.nf: # last video
|
||||
raise StopIteration
|
||||
else:
|
||||
path = self.files[self.count]
|
||||
self.new_video(path)
|
||||
ret_val, img0 = self.cap.read()
|
||||
path = self.files[self.count]
|
||||
self.new_video(path)
|
||||
ret_val, img0 = self.cap.read()
|
||||
|
||||
self.frame += 1
|
||||
s = f'video {self.count + 1}/{self.nf} ({self.frame}/{self.frames}) {path}: '
|
||||
@@ -390,7 +387,7 @@ class LoadStreams:
|
||||
|
||||
def img2label_paths(img_paths):
|
||||
# Define label paths as a function of image paths
|
||||
sa, sb = os.sep + 'images' + os.sep, os.sep + 'labels' + os.sep # /images/, /labels/ substrings
|
||||
sa, sb = f'{os.sep}images{os.sep}', f'{os.sep}labels{os.sep}' # /images/, /labels/ substrings
|
||||
return [sb.join(x.rsplit(sa, 1)).rsplit('.', 1)[0] + '.txt' for x in img_paths]
|
||||
|
||||
|
||||
@@ -456,7 +453,7 @@ class LoadImagesAndLabels(Dataset):
|
||||
|
||||
# Display cache
|
||||
nf, nm, ne, nc, n = cache.pop('results') # found, missing, empty, corrupt, total
|
||||
if exists and LOCAL_RANK in (-1, 0):
|
||||
if exists and LOCAL_RANK in {-1, 0}:
|
||||
d = f"Scanning '{cache_path}' images and labels... {nf} found, {nm} missing, {ne} empty, {nc} corrupt"
|
||||
tqdm(None, desc=prefix + d, total=n, initial=n, bar_format=BAR_FORMAT) # display cache results
|
||||
if cache['msgs']:
|
||||
|
||||
Reference in new issue
Block a user