r/code • u/Commercial-Creme-635 • Nov 23 '23
Help Please Noob Programmer LWK
Hey guys, I'm trying to code an image analysis algorithm but I'm have trouble with handling the data and files and stuff. This is probably a very beginner level problem but I'm trying to split my data according to the 80-20 split but it keeps telling me that my pathway doesn't exist? I'll add my code as well as the error I'm getting. Any help is appreciated.
*windows username and folder names censored for privacy*
import os
from sklearn.model_selection import train_test_split
import shutil
base_folder = r'C:\Users\NAME\Documents'
dataset_folder = 'C:\\PROJECT\\data\\faw_01'
dataset_path = os.path.join(base_folder, dataset_folder)
train_set_path = r'C:\Users\NAME\Documents\PROJECT\train_set'
test_set_path = r'C:\Users\NAME\Documents\PROJECT\test_set'
print("Base folder:", base_folder)
print("Dataset folder:", dataset_folder)
print("Dataset path:", dataset_path)
print("Train set path:", train_set_path)
print("Test set path:", test_set_path)
os.makedirs(train_set_path, exist_ok=True)
os.makedirs(test_set_path, exist_ok=True)
all_files = os.listdir(dataset_path)
train_files, test_files = train_test_split(all_files, test_size = 0.2, random_state = 42)
for file_name in train_files:
source_path = os.path.join(dataset_path, file_name)
destination_path = os.path.join(train_set_path, file_name)
shutil.copyfile(source_path, destination_path)
for file_name in test_files:
source_path = os.path.join(dataset_path, file_name)
destination_path = os.path.join(test_set_path, file_name)
shutil.copyfile(source_path, destination_path)
error:
Traceback (most recent call last):
File "c:\Users\NAME\OneDrive\Documents\PROJECT\Test\split.py", line 22, in <module>
all_files = os.listdir(dataset_path)
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\PROJECT\\data\\faw_01'
View all comments
Show parent comment
2
u/Commercial-Creme-635 Nov 23 '23
thank you so much for the advice!