8.7 KiB
8.7 KiB
import os
import pandas as pd
import shutil
import json
data = pd.read_csv(r'C:\Users\PC\Desktop\wko_test_data\train\_classes.csv', encoding='utf-8')
for category in list(data.columns[1:]):
os.mkdir(f"./data/train/{category.strip().capitalize()}")
for file in data.iloc:
file_name = file[0]
for item in list(file.items())[1:]:
if item[1]:
shutil.copyfile(rf'C:\Users\PC\Desktop\wko_test_data\train\\{file_name}', f'./data/train/{item[0].strip().capitalize()}/{file_name}')
data_test = pd.read_csv(r'C:\Users\PC\Desktop\wko_test_data\test\_classes.csv', encoding='utf-8')
results = []
for file in data_test.iloc:
file_name = file[0]
for item in list(file.items())[1:]:
shutil.copyfile(rf'C:\Users\PC\Desktop\wko_test_data\test\\{file_name}', f'./data/test/{file_name}')
if item[1]:
results.append({'filename': file_name, "value": item[0].strip().capitalize()})
continue
with open("./data/test_label.json", 'w', encoding='utf-8') as f:
json.dump(results, f)
data_count = len(os.listdir(r'D:\Michal\studia\wk_project_data\Fish_Data\images\cropped'))
round(data_count *0.8)
3362
results = []
os.listdir(r'D:\Michal\studia\wk_project_data\Fish_Data\images\cropped')
for fish in os.listdir(r'D:\Michal\studia\wk_project_data\Fish_Data\images\cropped')[:3362]:
shutil.copyfile(rf'D:\Michal\studia\wk_project_data\Fish_Data\images\cropped\\{fish}', f'./new_data/train/Fish/{fish}')
for fish in os.listdir(r'D:\Michal\studia\wk_project_data\Fish_Data\images\cropped')[3363:]:
shutil.copyfile(rf'D:\Michal\studia\wk_project_data\Fish_Data\images\cropped\\{fish}', f'./new_data/test/{fish}')
results.append({'filename': fish, "value": 'Fish'})
for jellyfish in os.listdir(r'D:\Michal\studia\wk_project_data\jellyfish\data\val\animal_jellyfish'):
shutil.copyfile(rf'D:\Michal\studia\wk_project_data\jellyfish\data\val\animal_jellyfish\\{jellyfish}', f'./new_data/train/Jellyfish/{jellyfish}')
for jellyfish in os.listdir(r'D:\Michal\studia\wk_project_data\jellyfish\data\test\animal_jellyfish'):
shutil.copyfile(rf'D:\Michal\studia\wk_project_data\jellyfish\data\test\animal_jellyfish\\{jellyfish}', f'./new_data/test/{jellyfish}')
results.append({'filename': jellyfish, "value": 'Jellyfish'})
for lionfish in os.listdir(r'D:\Michal\studia\wk_project_data\lionfish\data\val\lionfish'):
shutil.copyfile(rf'D:\Michal\studia\wk_project_data\lionfish\data\val\lionfish\\{lionfish}', f'./new_data/train/Lionfish/{lionfish}')
for lionfish in os.listdir(r'D:\Michal\studia\wk_project_data\lionfish\data\test\lionfish'):
shutil.copyfile(rf'D:\Michal\studia\wk_project_data\lionfish\data\test\lionfish\\{lionfish}', f'./new_data/test/{lionfish}')
results.append({'filename': lionfish, "value": 'Lionfish'})
for shark in os.listdir(r'D:\Michal\studia\wk_project_data\shark\data\val\animal_shark'):
shutil.copyfile(rf'D:\Michal\studia\wk_project_data\shark\data\val\animal_shark\\{shark}', f'./new_data/train/Shark/{shark}')
for shark in os.listdir(r'D:\Michal\studia\wk_project_data\shark\data\test\animal_shark'):
shutil.copyfile(rf'D:\Michal\studia\wk_project_data\shark\data\test\animal_shark\\{shark}', f'./new_data/test/{shark}')
results.append({'filename': shark, "value": 'Shark'})
for stingray in os.listdir(r'D:\Michal\studia\wk_project_data\stingray\data\val\stingray'):
shutil.copyfile(rf'D:\Michal\studia\wk_project_data\stingray\data\val\stingray\\{stingray}', f'./new_data/train/Stingray/{stingray}')
for stingray in os.listdir(r'D:\Michal\studia\wk_project_data\stingray\data\test\stingray'):
shutil.copyfile(rf'D:\Michal\studia\wk_project_data\stingray\data\test\stingray\\{stingray}', f'./new_data/test/{stingray}')
results.append({'filename': stingray, "value": 'Stingray'})
round(len(os.listdir(r'D:\Michal\studia\wk_project_data\turtle\images')) *0.8)
1582
for turtle in os.listdir(r'D:\Michal\studia\wk_project_data\turtle\images')[:600]:
shutil.copyfile(rf'D:\Michal\studia\wk_project_data\turtle\images\\{turtle}', f'./new_data/train/Turtle/{turtle}')
for turtle in os.listdir(r'D:\Michal\studia\wk_project_data\turtle\images')[600:700]:
shutil.copyfile(rf'D:\Michal\studia\wk_project_data\turtle\images\\{turtle}', f'./new_data/test/{turtle}')
results.append({'filename': turtle, "value": 'Turtle'})
with open("./new_data/test_labels.json", 'w', encoding='utf-8') as f:
json.dump(results, f)