File size: 1,417 Bytes
2ab2b33 |
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 32 33 34 35 36 37 38 |
"""
Author: Yagnik Poshiya
GitHub: @yagnikposhiya
Charotar University of Science and Technology
"""
import os
import shutil
import math
def split_dataset(input_dir, output_dir, files_per_directory):
if not os.path.exists(output_dir):
os.makedirs(output_dir)
files = os.listdir(input_dir)
num_files = len(files)
num_directories = math.ceil(num_files / files_per_directory)
for i in range(num_directories):
start_idx = i * files_per_directory
end_idx = min((i + 1) * files_per_directory, num_files)
subset_files = files[start_idx:end_idx]
directory_name = f"clips_{i}"
directory_path = os.path.join(output_dir, directory_name)
os.makedirs(directory_path)
for file_name in subset_files:
src_file_path = os.path.join(input_dir, file_name)
dest_file_path = os.path.join(directory_path, file_name)
shutil.copy(src_file_path, dest_file_path)
if __name__ == "__main__":
input_directory = "/home/yagnikposhiya/WorkStation/Datasets/SIH/CommonVoiceCorpusHindi15/clips" # Change this to your dataset directory
output_directory = "/home/yagnikposhiya/WorkStation/Datasets/SIH/CommonVoiceCorpusHindi15/clips2" # Change this to your desired output directory
files_per_directory = 10000 # Maximum files per directory
split_dataset(input_directory, output_directory, files_per_directory) |