updates
This commit is contained in:
parent
d5dfbedcda
commit
96263ff434
|
@ -352,7 +352,7 @@ class LoadImagesAndLabels(Dataset): # for training/testing
|
||||||
if extract_bounding_boxes:
|
if extract_bounding_boxes:
|
||||||
p = Path(self.img_files[i])
|
p = Path(self.img_files[i])
|
||||||
img = cv2.imread(str(p))
|
img = cv2.imread(str(p))
|
||||||
h, w, _ = img.shape
|
h, w = img.shape[:2]
|
||||||
for j, x in enumerate(l):
|
for j, x in enumerate(l):
|
||||||
f = '%s%sclassifier%s%g_%g_%s' % (p.parent.parent, os.sep, os.sep, x[0], j, p.name)
|
f = '%s%sclassifier%s%g_%g_%s' % (p.parent.parent, os.sep, os.sep, x[0], j, p.name)
|
||||||
if not os.path.exists(Path(f).parent):
|
if not os.path.exists(Path(f).parent):
|
||||||
|
@ -380,7 +380,7 @@ class LoadImagesAndLabels(Dataset): # for training/testing
|
||||||
assert img is not None, 'Image Not Found ' + img_path
|
assert img is not None, 'Image Not Found ' + img_path
|
||||||
r = self.img_size / max(img.shape) # size ratio
|
r = self.img_size / max(img.shape) # size ratio
|
||||||
if self.augment and r < 1: # if training (NOT testing), downsize to inference shape
|
if self.augment and r < 1: # if training (NOT testing), downsize to inference shape
|
||||||
h, w, _ = img.shape
|
h, w = img.shape[:2]
|
||||||
img = cv2.resize(img, (int(w * r), int(h * r)), interpolation=cv2.INTER_LINEAR) # or INTER_AREA
|
img = cv2.resize(img, (int(w * r), int(h * r)), interpolation=cv2.INTER_LINEAR) # or INTER_AREA
|
||||||
self.imgs[i] = img
|
self.imgs[i] = img
|
||||||
|
|
||||||
|
@ -414,14 +414,14 @@ class LoadImagesAndLabels(Dataset): # for training/testing
|
||||||
if mosaic:
|
if mosaic:
|
||||||
# Load mosaic
|
# Load mosaic
|
||||||
img, labels = load_mosaic(self, index)
|
img, labels = load_mosaic(self, index)
|
||||||
h, w, _ = img.shape
|
h, w = img.shape[:2]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Load image
|
# Load image
|
||||||
img = load_image(self, index)
|
img = load_image(self, index)
|
||||||
|
|
||||||
# Letterbox
|
# Letterbox
|
||||||
h, w, _ = img.shape
|
h, w = img.shape[:2]
|
||||||
if self.rect:
|
if self.rect:
|
||||||
img, ratio, padw, padh = letterbox(img, self.batch_shapes[self.batch[index]], mode='rect')
|
img, ratio, padw, padh = letterbox(img, self.batch_shapes[self.batch[index]], mode='rect')
|
||||||
else:
|
else:
|
||||||
|
@ -512,7 +512,7 @@ def load_image(self, index):
|
||||||
assert img is not None, 'Image Not Found ' + img_path
|
assert img is not None, 'Image Not Found ' + img_path
|
||||||
r = self.img_size / max(img.shape) # size ratio
|
r = self.img_size / max(img.shape) # size ratio
|
||||||
if self.augment: # if training (NOT testing), downsize to inference shape
|
if self.augment: # if training (NOT testing), downsize to inference shape
|
||||||
h, w, _ = img.shape
|
h, w = img.shape[:2]
|
||||||
img = cv2.resize(img, (int(w * r), int(h * r)), interpolation=cv2.INTER_LINEAR) # _LINEAR fastest
|
img = cv2.resize(img, (int(w * r), int(h * r)), interpolation=cv2.INTER_LINEAR) # _LINEAR fastest
|
||||||
return img
|
return img
|
||||||
|
|
||||||
|
@ -762,14 +762,28 @@ def cutout(image, labels):
|
||||||
return labels
|
return labels
|
||||||
|
|
||||||
|
|
||||||
|
def reduce_img_size(path='../data/sm3/images', img_size=1024): # from utils.datasets import *; reduce_img_size()
|
||||||
|
# creates a new ./images_reduced folder with reduced size images of maximum size img_size
|
||||||
|
path_new = path + '_reduced' # reduced images path
|
||||||
|
create_folder(path_new)
|
||||||
|
for f in tqdm(glob.glob('%s/*.*' % path)):
|
||||||
|
try:
|
||||||
|
img = cv2.imread(f)
|
||||||
|
h, w = img.shape[:2]
|
||||||
|
r = img_size / max(h, w) # size ratio
|
||||||
|
if r < 1.0:
|
||||||
|
img = cv2.resize(img, (int(w * r), int(h * r)), interpolation=cv2.INTER_AREA) # _LINEAR fastest
|
||||||
|
cv2.imwrite(f.replace(path, path_new), img)
|
||||||
|
except:
|
||||||
|
print('WARNING: image failure %s' % f)
|
||||||
|
|
||||||
|
|
||||||
def convert_images2bmp():
|
def convert_images2bmp():
|
||||||
# cv2.imread() jpg at 230 img/s, *.bmp at 400 img/s
|
# cv2.imread() jpg at 230 img/s, *.bmp at 400 img/s
|
||||||
for path in ['../coco/images/val2014/', '../coco/images/train2014/']:
|
for path in ['../coco/images/val2014/', '../coco/images/train2014/']:
|
||||||
folder = os.sep + Path(path).name
|
folder = os.sep + Path(path).name
|
||||||
output = path.replace(folder, folder + 'bmp')
|
output = path.replace(folder, folder + 'bmp')
|
||||||
if os.path.exists(output):
|
create_folder(output)
|
||||||
shutil.rmtree(output) # delete output folder
|
|
||||||
os.makedirs(output) # make new output folder
|
|
||||||
|
|
||||||
for f in tqdm(glob.glob('%s*.jpg' % path)):
|
for f in tqdm(glob.glob('%s*.jpg' % path)):
|
||||||
save_name = f.replace('.jpg', '.bmp').replace(folder, folder + 'bmp')
|
save_name = f.replace('.jpg', '.bmp').replace(folder, folder + 'bmp')
|
||||||
|
|
Loading…
Reference in New Issue