]> AND Private Git Repository - myo-class.git/blob - reversesample.py
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
stable, day after meeting
[myo-class.git] / reversesample.py
1 from os import listdir as ls
2 from os.path import join, splitext
3 from shutil import move as mv, copyfile as cp
4 import pathlib
5
6 def move(indir, outdir, n, distinction_word='', copy=True):# move n ordered files from indir to outdir
7         l = sorted(ls(indir))
8         for filename in l[:n]:
9                 # print(join(indir, filename), join(outdir, filename))
10                 pathlib.Path(outdir).mkdir(parents=True, exist_ok=True)
11                 fname, fextension = splitext(filename)
12                 action = cp if copy else mv
13                 action(join(indir, filename), join(outdir, fname + distinction_word + fextension))
14
15 if __name__ == '__main__':
16         
17         move('./sample-crop-mask/train/infarctus', './generated/90/infarctus/crop-mask', 400) # move 400 ordered files from param 1 to param 2
18         move('./sample-crop-mask/train/noinfarctus', './generated/90/noinfarctus/crop-mask', 400)
19         move('./sample-crop-mask/valid/infarctus', './generated/90/infarctus/crop-mask', 100)
20         move('./sample-crop-mask/valid/noinfarctus', './generated/90/noinfarctus/crop-mask', 100)