0
# Summary Operations
1
2
TensorBoard's summary module provides access to summary writing infrastructure for creating TensorBoard logs. It re-exports summary operations from v1 and v2 APIs and provides writer classes for programmatic data logging. The module serves as the central entry point for TensorBoard's summary functionality.
3
4
## Capabilities
5
6
### V2 Summary Re-exports
7
8
TensorBoard re-exports v2 summary operations from the TensorFlow summary API.
9
10
```python { .api }
11
# Re-exported from tensorboard.summary.v2
12
# (actual implementations depend on TensorFlow installation)
13
from tensorboard.summary.v2 import *
14
```
15
16
Note: The v2 API functions are conditionally imported and depend on TensorFlow being available. When TensorFlow is not installed, these functions may not be available.
17
18
### Writer Classes
19
20
Core TensorBoard writer infrastructure for programmatic summary data writing.
21
22
```python { .api }
23
class Writer:
24
"""
25
Summary data writer for programmatic logging.
26
27
Provides interface for writing summary data with explicit control
28
over output destinations and buffering.
29
"""
30
31
def __init__(self, output):
32
"""
33
Initialize Writer with output destination.
34
35
Args:
36
output (Output or str): Output instance or directory path
37
"""
38
39
class Output:
40
"""
41
Abstract base class for summary output destinations.
42
43
Defines the interface for writing summary data to various targets.
44
"""
45
46
class DirectoryOutput(Output):
47
"""
48
File system output implementation.
49
50
Writes summary data to TensorBoard event files in specified directory.
51
"""
52
53
def __init__(self, path):
54
"""
55
Initialize DirectoryOutput.
56
57
Args:
58
path (str): Directory path for log files
59
"""
60
```
61
62
### V1 Summary Re-exports
63
64
TensorBoard re-exports v1 summary operations from the TensorFlow v1 summary API.
65
66
```python { .api }
67
# Re-exported from tensorboard.summary.v1
68
# (actual implementations depend on TensorFlow installation)
69
from tensorboard.summary.v1 import *
70
```
71
72
Note: The v1 API functions are conditionally imported and depend on TensorFlow being available. When TensorFlow is not installed, these functions may not be available.
73
74
## Usage Examples
75
76
### Basic Module Usage
77
78
```python
79
import tensorboard.summary as tb_summary
80
81
# Access writer classes
82
writer = tb_summary.Writer(tb_summary.DirectoryOutput('./logs'))
83
```
84
85
### V2 API Usage (if TensorFlow available)
86
87
```python
88
# Re-exported from tensorboard.summary.v2 (requires TensorFlow)
89
try:
90
from tensorboard.summary.v2 import scalar, histogram
91
scalar('loss', 0.1, step=1)
92
histogram('weights', model_weights, step=1)
93
except ImportError:
94
print("TensorFlow not available - v2 summary API unavailable")
95
```
96
97
### Writer Infrastructure
98
99
```python
100
from tensorboard.summary import Writer, DirectoryOutput
101
102
# Create writer with directory output
103
output = DirectoryOutput('./logs/experiment')
104
writer = Writer(output)
105
106
# Use writer for custom summary operations
107
# (specific writer methods depend on implementation)
108
```
109
110
### V1 API Usage (if TensorFlow available)
111
112
```python
113
# Re-exported from tensorboard.summary.v1 (requires TensorFlow)
114
try:
115
from tensorboard.summary.v1 import scalar, histogram
116
# Use v1 API functions
117
except ImportError:
118
print("TensorFlow not available - v1 summary API unavailable")
119
```
120
121
The summary module serves as TensorBoard's central entry point for summary operations, providing access to both v1/v2 APIs (when TensorFlow is available) and core writer infrastructure for programmatic logging.