This commit is contained in:
Glenn Jocher 2019-12-05 00:17:27 -08:00
parent 28c103108b
commit 2421f3e252
1 changed files with 21 additions and 17 deletions

View File

@ -758,24 +758,28 @@ def reduce_img_size(path='../data/sm4/images', img_size=1024): # from utils.dat
print('WARNING: image failure %s' % f) print('WARNING: image failure %s' % f)
def convert_images2bmp(): def convert_images2bmp(): # from utils.datasets import *; convert_images2bmp()
# cv2.imread() jpg at 230 img/s, *.bmp at 400 img/s # Save images
for path in ['../coco/images/val2014/', '../coco/images/train2014/']: formats = [x.lower() for x in img_formats] + [x.upper() for x in img_formats]
folder = os.sep + Path(path).name # for path in ['../coco/images/val2014', '../coco/images/train2014']:
output = path.replace(folder, folder + 'bmp') for path in ['../data/sm4/images', '../data/sm4/background']:
create_folder(output) create_folder(path + 'bmp')
for ext in formats: # ['.bmp', '.jpg', '.jpeg', '.png', '.tif', '.dng']
for f in tqdm(glob.glob('%s/*%s' % (path, ext)), desc='Converting %s' % ext):
cv2.imwrite(f.replace(ext.lower(), '.bmp').replace(path, path + 'bmp'), cv2.imread(f))
for f in tqdm(glob.glob('%s*.jpg' % path)): # Save labels
save_name = f.replace('.jpg', '.bmp').replace(folder, folder + 'bmp') # for path in ['../coco/trainvalno5k.txt', '../coco/5k.txt']:
cv2.imwrite(save_name, cv2.imread(f)) for file in ['../data/sm4/out_train.txt', '../data/sm4/out_test.txt']:
with open(file, 'r') as f:
for label_path in ['../coco/trainvalno5k.txt', '../coco/5k.txt']: lines = f.read()
with open(label_path, 'r') as file: # lines = f.read().replace('2014/', '2014bmp/') # coco
lines = file.read() lines = lines.replace('/images', '/imagesbmp')
lines = lines.replace('2014/', '2014bmp/').replace('.jpg', '.bmp').replace( lines = lines.replace('/background', '/backgroundbmp')
'/Users/glennjocher/PycharmProjects/', '../') for ext in formats:
with open(label_path.replace('5k', '5k_bmp'), 'w') as file: lines = lines.replace(ext, '.bmp')
file.write(lines) with open(file.replace('.txt', 'bmp.txt'), 'w') as f:
f.write(lines)
def imagelist2folder(path='data/coco_64img.txt'): # from utils.datasets import *; imagelist2folder() def imagelist2folder(path='data/coco_64img.txt'): # from utils.datasets import *; imagelist2folder()