Skip to content

Commit 8a41dc1

Browse files
committed
🐛 file does not exist
1 parent 796d708 commit 8a41dc1

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

image_split.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import shutil
33
from tqdm import tqdm
4+
45
def split_data():
56
# 원본 데이터셋 폴더와 저장할 폴더 지정
67
original_dataset_folder = 'C:/cv_project/Recycling_trash/Separate_Collection/trash_dataset'
@@ -11,29 +12,28 @@ def split_data():
1112
os.makedirs(train_folder)
1213

1314
# 각 batch 폴더를 돌면서 파일을 읽어와 train 폴더에 저장
14-
index = 0
15+
start_index = 0
1516
for batch_folder in tqdm(os.listdir(original_dataset_folder), desc="Processing batches"):
16-
batch_folder_name = f'batch_{batch_folder}'
17-
batch_folder_path = os.path.join(original_dataset_folder, batch_folder_name)
17+
batch_folder_path = os.path.join(original_dataset_folder, batch_folder)
1818

1919
# batch 폴더가 존재하는지 확인
20-
if os.path.exists(batch_folder_path):
20+
if os.path.isdir(batch_folder_path):
2121
# batch 폴더 안에 있는 파일들을 정렬
2222
file_list = sorted(os.listdir(batch_folder_path))
2323

2424
# train 폴더에 파일을 복사하면서 이름을 변경
2525
for i, file_name in enumerate(file_list):
2626
# 숫자 부분을 4자리로 맞추고 0을 추가
27+
index = start_index + i
2728
padded_number = f"{index:04d}" if index < 1000 else str(index)
2829
new_file_name = f"{padded_number}.jpg"
2930

3031
source_path = os.path.join(batch_folder_path, file_name)
3132
destination_path = os.path.join(train_folder, new_file_name)
3233
shutil.copyfile(source_path, destination_path)
3334

34-
# 다음 batch 폴더에서 시작할 인덱스 업데이트
35-
index += i
36-
35+
# 다음 batch 폴더에서 시작할 인덱스 업데이트
36+
start_index += len(file_list)
3737

3838
if __name__ == '__main__':
3939
split_data()

0 commit comments

Comments
 (0)