Created
February 21, 2019 11:44
-
-
Save budui/859963e306cc14ef891236dbc8cae2ad to your computer and use it in GitHub Desktop.
prepare dataset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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