# SillokBert-Scratch 프로젝트 6단계: TensorBoard 로그 추출 # ----------------------------------------------------------------- # 'logs' 폴더의 훈련 기록을 텍스트로 확인하기 위해 사용합니다. # ----------------------------------------------------------------- import os from pathlib import Path from tensorboard.backend.event_processing import event_accumulator def export_tensorboard_logs_to_text(log_dir: str): """지정된 디렉토리에서 TensorBoard 이벤트 파일을 찾아 스칼라 값을 출력합니다.""" log_path = Path(log_dir) if not log_path.exists() or not log_path.is_dir(): print(f"[에러] 로그 디렉토리를 찾을 수 없습니다: {log_dir}") return print(f"--- 6. TensorBoard Log Export ---") print(f"대상 디렉토리: {log_dir}") try: event_file = next(log_path.glob("events.out.tfevents.*")) except StopIteration: print(f"[에러] '{log_dir}'에서 이벤트 파일을 찾을 수 없습니다.") return acc = event_accumulator.EventAccumulator(str(event_file), size_guidance={'scalars': 0}) acc.Reload() scalar_tags = acc.Tags()['scalars'] print(f"\n추출된 지표: {scalar_tags}") print("-" * 40) for tag in sorted(scalar_tags): events = acc.Scalars(tag) print(f"\n[지표: {tag}]") print(" Step | Value") print("-------|---------") for event in events: print(f" {event.step:<5} | {event.value:.6f}") print("\n--- 분석 완료 ---") if __name__ == "__main__": # 허깅페이스 리포지토리의 'logs' 폴더를 참조하도록 상대 경로로 설정 target_log_directory = "./logs" export_tensorboard_logs_to_text(target_log_directory)