vlbthambawita's picture
added data
d47d089
import pandas as pd
import os
import shutil
def split_csv(input_file, train_file, validate_file, test_file, train_size, validate_size, test_size):
# Read the input CSV file
data = pd.read_csv(input_file)
# Split the data into train, validate, and test subsets
train_data = data.iloc[:train_size]
validate_data = data.iloc[train_size:train_size + validate_size]
test_data = data.iloc[train_size + validate_size:train_size + validate_size + test_size]
# Save the subsets to separate CSV files
train_data.to_csv(train_file, index=False)
validate_data.to_csv(validate_file, index=False)
test_data.to_csv(test_file, index=False)
def copy_ecg_files(csv_file, destination_folder, src_folder):
# Read the CSV file
data = pd.read_csv(csv_file)
# Create the destination folder if it doesn't exist
if not os.path.exists(destination_folder):
os.makedirs(destination_folder)
# Copy the corresponding ECG files to the destination folder
for index, row in data.iterrows():
ecg_file = str(row['patid']) + ".asc" # Replace 'ecg_filename' with the appropriate column name containing the ECG file names
src_path = os.path.join(src_folder, ecg_file)
dst_path = os.path.join(destination_folder, ecg_file)
shutil.copy(src_path, dst_path)
if __name__ == '__main__':
# Set the input CSV file and the source folder
dst_dir = '/work/vajira/data/deepfake_ecg_full_train_validation_test'
input_file = '/work/vajira/data/Deepfake-ecg/filtered_all_normals_121977_ground_truth.csv' # Change this to the name of your CSV file
train_file = f'{dst_dir}/train.csv'
validate_file = f'{dst_dir}/validate.csv'
test_file = f'{dst_dir}/test.csv'
src_folder = '/work/vajira/data/Deepfake-ecg/filtered_all_normals_121977/from_006_chck_2500_150k_filtered_all_normals_121977' # Change this to the name of the folder containing the ECG files
# Set the sizes of the train, validate, and test subsets from full size of the dataset 121977
train_size = 97581 # 80% of 121977=97581
validate_size = 12198 # 10% of 121977=12198
test_size = 12198 # 10% of 121977=12198
split_csv(input_file, train_file, validate_file, test_file, train_size, validate_size, test_size)
# Call the copy_ecg_files function to copy the ECG files into the corresponding folders
copy_ecg_files(train_file, f'{dst_dir}/train', src_folder)
copy_ecg_files(validate_file, f'{dst_dir}/validation', src_folder)
copy_ecg_files(test_file, f'{dst_dir}/test', src_folder)