File size: 1,845 Bytes
170de4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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)