Skip to content

Instantly share code, notes, and snippets.

@budui
Created February 21, 2019 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save budui/859963e306cc14ef891236dbc8cae2ad to your computer and use it in GitHub Desktop.
Save budui/859963e306cc14ef891236dbc8cae2ad to your computer and use it in GitHub Desktop.
prepare dataset
import os
from shutil import copyfile
def _make_sure_dir_exist(path):
if not os.path.isdir(path):
os.mkdir(path)
def refactor_dataset_folder(root_path, classes_map, img_path_root=None):
if not os.path.isdir(root_path):
raise NotADirectoryError(root_path + " do not exists")
for c in classes_map:
class_root = os.path.join(root_path, c)
_make_sure_dir_exist(class_root)
for img_path in classes_map[c]:
if img_path_root is not None:
real_img_path = os.path.join(img_path_root, img_path)
else:
real_img_path = img_path
copyfile(real_img_path, os.path.join(class_root, os.path.basename(img_path)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment