-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValidation.py
31 lines (23 loc) · 912 Bytes
/
Validation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
import shutil
import pandas as pd
os.chdir("path")
# Define the CSV file path
csv_file_path = "path"
# Define the path of the new directory to copy the validation images
validation_dir = "path"
# Load the CSV file into a DataFrame
df = pd.read_csv(csv_file_path)
# Get the rows where the value of the 'validation' column is 'yes'
validation_rows = df.loc[df['marker'] == 'yes']
# Create the validation directory if it doesn't exist
if not os.path.exists(validation_dir):
os.mkdir(validation_dir)
# Loop through the rows and copy the images to the validation directory
for index, row in validation_rows.iterrows():
image_path = row['filename']
image_filename = os.path.basename(image_path)
validation_path = os.path.join(validation_dir, image_filename)
print (image_path)
shutil.copy2(image_path, validation_path)
print('Validation images have been copied successfully.')