def preprocess(image_dir, new_image_dir, preprocess_fn):
image_paths = []
labels = []
if os.path.isdir(new_image_dir):
rmtree(new_image_dir)
os.makedirs(new_image_dir)
classes = os.listdir(image_dir)
for clas in classes:
class_dir = os.path.join(image_dir, str(clas))
new_class_dir = os.path.join(new_image_dir, str(clas))
os.makedirs(new_class_dir)
for image_name in os.listdir(class_dir):
image = misc.imread(os.path.join(class_dir, image_name))
image = preprocess_fn(image)
misc.imsave(os.path.join(new_class_dir, image_name), image)
评论列表
文章目录