openface/util/prune-dataset.py

29 lines
939 B
Python
Raw Normal View History

#!/usr/bin/env python3
import argparse
import os
import shutil
if __name__ == '__main__':
parser = argparse.ArgumentParser()
2015-10-14 10:34:30 +08:00
parser.add_argument('inPlaceDir', type=str,
help="Directory to prune in-place.")
2015-10-29 19:50:15 +08:00
parser.add_argument('--numImagesThreshold', type=int,
help="Delete directories with less than this many images.",
default=10)
args = parser.parse_args()
exts = ["jpg", "png"]
for subdir, dirs, files in os.walk(args.inPlaceDir):
2015-10-14 10:34:30 +08:00
if subdir == args.inPlaceDir:
continue
nImgs = 0
for fName in files:
(imageClass, imageName) = (os.path.basename(subdir), fName)
if any(imageName.lower().endswith("." + ext) for ext in exts):
nImgs += 1
if nImgs < args.numImagesThreshold:
print("Removing {}".format(subdir))
shutil.rmtree(subdir)