-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathPreprocess.py
More file actions
33 lines (28 loc) · 1.1 KB
/
Preprocess.py
File metadata and controls
33 lines (28 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import shutil
from tqdm import tqdm
import cv2
class PreprocessData:
def __init__(self, paths):
self.paths = paths
def resize_data(self, size):
for path in self.paths:
print('Resizing {}'.format(path))
src_path = os.path.abspath(path)
dst_path = src_path + 'Resize'
shutil.rmtree(dst_path, ignore_errors=True)
os.mkdir(dst_path)
filenames = os.listdir(src_path)
for filename in tqdm(filenames):
src_filepath = os.path.join(src_path, filename)
dst_filepath = os.path.join(dst_path, filename)
try:
img = cv2.imread(src_filepath)
img = cv2.resize(img, size)
cv2.imwrite(dst_filepath, img)
except:
pass
if __name__ == '__main__':
resize_paths = ['./Data/train', './Data/test'] # Give the path where the data folders are present
p = PreprocessData(resize_paths)
p.resize_data((224, 224)) # Specify the size you would like to resize the images to