API Reference
This section contains detailed reference documentation for DAG logging to files in Graphbook.
- class graphbook.logging.DAGLogger(name: str | None = None, log_dir: str | None = 'logs')
Logs images in a directed acyclic graph (DAG) to a pyarrow format which can be read by Graphbook.
- node(name: str, doc: str = '', *back_refs: List[DAGNodeRef]) DAGNodeRef
Creates a node in the DAG ready for logging
- Parameters:
name – Name of the node
doc – Documentation or any description of the node
back_refs – List of references that are dependencies of this node
- Returns:
Reference to the node
- Return type:
- class graphbook.logging.DAGNodeRef(id: str, name: str, doc: str, filepath: Path, lock, *back_refs: List[DAGNodeRef])
Reference to a DAG node capable of logging images. You should not create this directly, but instead use the
graphbook.logging.DAGLogger.node()
to create one.- Parameters:
id – Unique identifier for the node
name – Name of the node
doc – Documentation or any description of the node
filepath – Path to the log file
lock – Lock to synchronize access to the log file
back_refs – List of references that are dependencies of this node
- class graphbook.logging.torch.TensorDAGNodeRef(id: str, name: str, doc: str, filepath: Path, lock, *back_refs: List[TensorDAGNodeRef])
Inherits from DAGNodeRef and adds the ability to log PIL images or tensors. You should not create this directly, but instead use the
graphbook.logging.torch.TransformsLogger.node()
to create one.
- class graphbook.logging.torch.TransformsLogger(name: str | None = None, log_dir: str | None = 'logs', log_every: int = 1)
A DAG logger designed specifically to log the image outputs from torchvision transforms.
- Parameters:
name – Name of the DAG. Will randomly generate an ID if not provided
log_dir – Directory to store the log files. Defaults to logs/
log_every – Log every nth transform. Defaults to 1 (log every time).
Example
from torchvision import transforms as T import torch from PIL import Image import graphbook as gb l = gb.TransformsLogger() transforms = T.Compose([ T.ToTensor(), T.CenterCrop(600), T.Grayscale(), T.RandomHorizontalFlip(p=1), ]) transforms = l.log(transforms) img_path = "<YOUR_IMAGE_PATH>" img = Image.open(img_path) img = transforms(img)
- log(transform: Transform | Compose | Compose)
Sets up the transforms to log the image outputs.
- Parameters:
transform – A torchvision transform or a sequence of transforms
- node(name: str, doc: str, *back_refs: List[TensorDAGNodeRef]) TensorDAGNodeRef
Creates a new node in the DAG that can log PIL images or tensors.
- Parameters:
name – Name of the node
doc – Description of the node
back_refs – List of back references to other nodes
- Returns:
The reference to the new node
- Return type: