K0nkere / DL_Dice-detection-project

DnD dice detection with CNN and transfer learning / Project for ML Bookcamp
0 stars 0 forks source link

How to: directories, files, paths #5

Open K0nkere opened 1 year ago

K0nkere commented 1 year ago

description of os.path functions

train_dir = Path('./images/training') submit_dir = Path('./images/submit')

submit_dir.mkdir(parents=True, exist_ok=True)

for label in ['healthy', 'multiple_diseases', 'rust', 'scab']: d = train_dir / label d.mkdir(parents=True, exist_ok=True)

- moving files

for i in tqdm(train_df.index): img = train_df.image_id[i] + '.jpg' img_path = img_dir / img for label in ['healthy', 'multiple_diseases', 'rust', 'scab']: if train_df[label][i] == 1: new_path = train_dir.absolute() / label / img shutil.move(img_path, new_path)

- splitting files in the folder into train, val, test sets and moving

splitfolders.ratio(train_dir, output='./images/tmp', move=True, ratio=(0.8,0.1,0.1))

shutil.rmtree(train_dir) os.rename('./images/tmp', train_dir)