Torch-Memo

Torch Memo

Preliminaries

  • .__dir__(): Getting all the functions in the module (Tool function)

TensorBoard

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from torch.utils.tensorboard import SummaryWriter
import numpy as np
from PIL import Image

writer = SummaryWriter("logs")

def compute(x):
return (torch.sin(torch.tensor(x)) + torch.randn(1) * torch.sin(torch.tensor(x)))


# writer.add_scalar()
for i in range(100):
writer.add_scalar("y=x", compute(i).item(), i)


# writer.add_image()
img = Image.open("003.jpg")
img_array = np.array(img)

# dataformats is HWC
writer.add_image("test", img_array, 1, dataformats='HWC')


Torch-Memo
https://xiyuanyang-code.github.io/posts/Torch-memo/
Author
Xiyuan Yang
Posted on
April 1, 2025
Updated on
April 1, 2025
Licensed under