
'apple':0, 'hallabong':1, 'onjumilgam':2, 'pear':3,'persimmon':4}

## roboflow 활용 **손** 어노테이션 파일에서 클래스 아이디 1-> 5로 수정
import os
# 어노테이션 파일이 있는 디렉토리 경로
ann_dir = r"C:\classes\FINAL_PROJECT\Data\AIHUB_Fruit\1.Training\Final_Data_before_aug\hand.v2i.yolov8\train\labels"
# 디렉토리 내의 모든 파일을 순회
for filename in os.listdir(ann_dir):
if filename.endswith(".txt"): # .txt 파일만 처리
file_path = os.path.join(ann_dir, filename)
# 파일 내용 읽기
with open(file_path, 'r') as file:
lines = file.readlines()
# 클래스 ID가 1인 것을 5로 바꿈
new_lines = []
for line in lines:
parts = line.split()
if len(parts) > 0 and parts[0] == '1': # 첫 번째 항목이 클래스 ID임을 확인
parts[0] = '5' # 클래스 ID를 5로 변경
new_lines.append(" ".join(parts) + '\n')
# 변경된 내용으로 파일 덮어쓰기
with open(file_path, 'w') as file:
file.writelines(new_lines)
print("클래스 ID 변경이 완료되었습니다.")
