Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- from pathlib import Path
- from shutil import copy2
- from random import shuffle
- def main():
- imgs = list(Path('./img_data').glob('**/*.jpg'))
- if not imgs:
- return
- shuffle(imgs)
- trainImgDir = Path('./train_img_data')
- testImgDir = Path('./test_img_data')
- for i in range(1, 100 + 1):
- d = f'{i:03d}_data'
- trainImgDir.joinpath(d).mkdir(parents=True, exist_ok=True)
- testImgDir.joinpath(d).mkdir(parents=True, exist_ok=True)
- imgs_len_80 = len(imgs) * 4 / 5
- for i, p in enumerate(imgs):
- if i < imgs_len_80:
- copy2(p, trainImgDir.joinpath(*p.parts[-2:]))
- continue
- copy2(p, testImgDir.joinpath(*p.parts[-2:]))
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement