더북(TheBook)

XML 파싱

다음 코드는 각각의 이미지 파일과 그에 해당하는 XML 주석 파일의 경로를 가져옵니다.

# 학습 데이터의 이미지와 XML 파일 경로를 획득합니다.
image_file_path_list = sorted([x for x in glob(train_x_path + '/**')])
subset_size = len(image_file_path_list) // 70 # 전체 데이터의 약 1/70만 사용
image_file_path_list = image_file_path_list[:subset_size]
xml_file_path_list = sorted([x for x in glob(train_y_path + '/**')])
xml_file_path_list = xml_file_path_list[:subset_size]

# 테스트 데이터의 이미지와 XML 파일 경로를 획득합니다.
test_image_file_path_list = sorted([x for x in glob(test_x_path + '/**')])
subset_size = len(test_image_file_path_list) // 70  # 전체 데이터의 약 1/70만 사용
test_image_file_path_list = test_image_file_path_list[:subset_size]
test_xml_file_path_list = sorted([x for x in glob(test_y_path + '/**')])
test_xml_file_path_list = test_xml_file_path_list[:subset_size]

glob 함수를 사용하여 지정된 경로에서 모든 파일의 경로를 리스트 형태로 가져옵니다. 데이터 세트의 사이즈가 크므로 전체 데이터의 약 만을 사용하여 실험의 효율성을 높입니다. 테스트 데이터에 대해서도 동일한 작업을 수행합니다.

신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.