Open K0nkere opened 1 year ago
description of os.path functions
from pathlib import Path path = Path(__file__).resolve()
from pathlib import Path path = Path(__file__).parent
import os dir_path = os.path.dirname(os.path.realpath(__file__))
path_to_script = os.path.split(__file__)[0] pre_parent = os.path.split(path_to_script)[0]
from pathlib import Path
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)
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)
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)
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)