:doc:`/beginner/deep_learning_60min_blitz` ์์๋ ๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฌ์ค๊ณ , nn.Module
์
์๋ธํด๋์ค(subclass)๋ก ์ ์ํ ๋ชจ๋ธ์ ๋ฐ์ดํฐ๋ฅผ ๊ณต๊ธ(feed)ํ๊ณ , ํ์ต ๋ฐ์ดํฐ๋ก ๋ชจ๋ธ์ ํ์ตํ๊ณ
ํ
์คํธ ๋ฐ์ดํฐ๋ก ํ
์คํธ๋ฅผ ํ๋ ๋ฐฉ๋ฒ๋ค์ ์ดํด๋ดค์ต๋๋ค. ์งํ ์ํฉ์ ์ดํด๋ณด๊ธฐ ์ํด,
ํ์ต์ด ์งํ ์ค์ผ ๋ ํ์ต์ด ์ ๋๊ณ ์๋์ง๋ฅผ ์์๋ณด๊ธฐ ์ํด ๋ช๋ช ์์น๋ค(statistic)์ ์ถ๋ ฅํ์ต๋๋ค.
ํ์ง๋ง ๋ ๋์ ๋ฐฉ๋ฒ๋ ์์ต๋๋ค: PyTorch๋ ์ ๊ฒฝ๋ง ํ์ต ๋ด์ญ์ ์๊ฐํํ๋ ๋๊ตฌ์ธ TensorBoard์
ํตํฉ๋์์ต๋๋ค. ์ด ํํ ๋ฆฌ์ผ์์๋ PyTorch์ torchvision.datasets ์์ ์ฌ์ฉ ๊ฐ๋ฅํ
Fashion-MNIST dataset ์ผ๋ก
์ผ๋ถ ๊ธฐ๋ฅ์ ์ค๋ช
ํ๊ฒ ์ต๋๋ค.
์ด ํํ ๋ฆฌ์ผ์์๋ ๋ค์์ ๋ด์ฉ๋ค์ ๋ฐฐ์๋๋ค:
- (์ด์ ํํ ๋ฆฌ์ผ๊ณผ ๊ฑฐ์ ๋น์ทํ๊ฒ) ๋ฐ์ดํฐ๋ฅผ ์ฝ๊ณ ์ ์ ํ ๋ณํํฉ๋๋ค.
- TensorBoard๋ฅผ ์ค์ (set up)ํฉ๋๋ค.
- TensorBoard์ ๊ธฐ๋ก(write)ํฉ๋๋ค.
- TensorBoard๋ฅผ ์ฌ์ฉํ์ฌ ๋ชจ๋ธ ๊ตฌ์กฐ๋ฅผ ์ดํด๋ด ๋๋ค.
- ์ฝ๊ฐ์ ์ฝ๋๋ฅผ ์ถ๊ฐํ์ฌ TensorBoard์์ ์ด์ ํํ ๋ฆฌ์ผ์์ ๋ง๋ ์๊ฐํ์ ๋ํ์(interactive) ๋ฒ์ ์ ๋ง๋ญ๋๋ค.
๊ตฌ์ฒด์ ์ผ๋ก #5์์๋ ๋ค์ ๋ด์ฉ๋ค์ ์ดํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค:
- ํ์ต ๋ฐ์ดํฐ๋ฅผ ๊ฒ์ฌ(inspect)ํ๋ ๋ช ๊ฐ์ง ๋ฐฉ๋ฒ
- ํ์ต์ ๋ฐ๋ฅธ ๋ชจ๋ธ์ ์ฑ๋ฅ์ ์ถ์ (track)ํ๋ ๋ฐฉ๋ฒ
- ํ์ต์ด ์๋ฃ๋ ๋ชจ๋ธ์ ์ฑ๋ฅ์ ํ๊ฐ(assess)ํ๋ ๋ฐฉ๋ฒ
:doc:`/beginner/blitz/cifar10_tutorial` ์ ๋น์ทํ ์ฝ๋๋ก ์์ํด๋ณด๊ฒ ์ต๋๋ค:
# imports
import matplotlib.pyplot as plt
import numpy as np
import torch
import torchvision
import torchvision.transforms as transforms
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
# transforms
transform = transforms.Compose(
[transforms.ToTensor(),
transforms.Normalize((0.5,), (0.5,))])
# datasets
trainset = torchvision.datasets.FashionMNIST('./data',
download=True,
train=True,
transform=transform)
testset = torchvision.datasets.FashionMNIST('./data',
download=True,
train=False,
transform=transform)
# dataloaders
trainloader = torch.utils.data.DataLoader(trainset, batch_size=4,
shuffle=True, num_workers=2)
testloader = torch.utils.data.DataLoader(testset, batch_size=4,
shuffle=False, num_workers=2)
# ๋ถ๋ฅ ๊ฒฐ๊ณผ๋ฅผ ์ํ ์์
classes = ('T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle Boot')
# ์ด๋ฏธ์ง๋ฅผ ๋ณด์ฌ์ฃผ๊ธฐ ์ํ ํฌํผ(helper) ํจ์
# (์๋ `plot_classes_preds` ํจ์์์ ์ฌ์ฉ)
def matplotlib_imshow(img, one_channel=False):
if one_channel:
img = img.mean(dim=0)
img = img / 2 + 0.5 # unnormalize
npimg = img.numpy()
if one_channel:
plt.imshow(npimg, cmap="Greys")
else:
plt.imshow(np.transpose(npimg, (1, 2, 0)))
์ด์ ํํ ๋ฆฌ์ผ๊ณผ ์ ์ฌํ ๋ชจ๋ธ ๊ตฌ์กฐ๋ฅผ ์ ์ํ๋, ์ด๋ฏธ์ง์ ์ฑ๋์ด 3๊ฐ์์ 1๊ฐ๋ก, ํฌ๊ธฐ๊ฐ 32x32์์ 28x28๋ก ๋ณ๊ฒฝ๋ ๊ฒ์ ์ ์ฉํ ์ ์๋๋ก ์ฝ๊ฐ๋ง ์์ ํ๊ฒ ์ต๋๋ค:
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.conv1 = nn.Conv2d(1, 6, 5)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(6, 16, 5)
self.fc1 = nn.Linear(16 * 4 * 4, 120)
self.fc2 = nn.Linear(120, 84)
self.fc3 = nn.Linear(84, 10)
def forward(self, x):
x = self.pool(F.relu(self.conv1(x)))
x = self.pool(F.relu(self.conv2(x)))
x = x.view(-1, 16 * 4 * 4)
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = self.fc3(x)
return x
net = Net()
๋์ผํ optimizer
์ criterion
์ ์ ์ํฉ๋๋ค:
criterion = nn.CrossEntropyLoss()
optimizer = optim.SGD(net.parameters(), lr=0.001, momentum=0.9)
์ด์ torch.utils
์ tensorboard
๋ฅผ ๋ถ๋ฌ์ค๊ณ , TensorBoard์ ์ ๋ณด๋ฅผ
์ ๊ณต(write)ํ๋ SummaryWriter
๋ฅผ ์ฃผ์ํ ๊ฐ์ฒด์ธ SummaryWriter
๋ฅผ ์ ์ํ์ฌ
TensorBoard๋ฅผ ์ค์ ํฉ๋๋ค.
from torch.utils.tensorboard import SummaryWriter
# ๊ธฐ๋ณธ `log_dir` ์ "runs"์ด๋ฉฐ, ์ฌ๊ธฐ์๋ ๋ ๊ตฌ์ฒด์ ์ผ๋ก ์ง์ ํ์์ต๋๋ค
writer = SummaryWriter('runs/fashion_mnist_experiment_1')
์ ํ(line)์ runs/fashion_mnist_experiment_1
ํด๋๋ฅผ ์์ฑํฉ๋๋ค.
์ด์ TensorBoard์ ์ด๋ฏธ์ง(๊ตฌ์ฒด์ ์ผ๋ก๋ make_grid ๋ฅผ ์ฌ์ฉํ์ฌ ๊ทธ๋ฆฌ๋(grid))๋ฅผ ์จ๋ณด๊ฒ ์ต๋๋ค.
# ์์์ ํ์ต ์ด๋ฏธ์ง๋ฅผ ๊ฐ์ ธ์ต๋๋ค
dataiter = iter(trainloader)
images, labels = next(dataiter)
# ์ด๋ฏธ์ง ๊ทธ๋ฆฌ๋๋ฅผ ๋ง๋ญ๋๋ค.
img_grid = torchvision.utils.make_grid(images)
# ์ด๋ฏธ์ง๋ฅผ ๋ณด์ฌ์ค๋๋ค.
matplotlib_imshow(img_grid, one_channel=True)
# tensorboard์ ๊ธฐ๋กํฉ๋๋ค.
writer.add_image('four_fashion_mnist_images', img_grid)
์ด์ ๋ช ๋ น์ค(command line)์์
tensorboard --logdir=runs
๋ฅผ ์คํํ๊ณ , http://localhost:6006 ์ ์ด์ด๋ณด๋ฉด ๋ค์๊ณผ ๊ฐ์ ํ๋ฉด์ด ๋ํ๋ฉ๋๋ค.
์ง๊ธ๊น์ง TensorBoard๋ฅผ ์ด๋ป๊ฒ ์ฌ์ฉํ๋์ง๋ฅผ ์์๋ณด์์ต๋๋ค! ๊ทธ๋ฌ๋, ์ด ์์ ๋ Jupyter Notebook์์๋ ๊ฐ๋ฅํฉ๋๋ค - TensorBoard๋ ๋ํํ ์๊ฐํ๋ฅผ ๋ง๋๋๋ฐ ํนํ ๋ฐ์ด๋ฉ๋๋ค. ๋ค์์ ๊ทธ๋ฐ ๊ธฐ๋ฅ๋ค ์ค ํ๋๋ฅผ ์ดํด๋ณด๊ณ , ํํ ๋ฆฌ์ผ์ ๋๋จธ์ง ๋ถ๋ถ์์ ๋ช ๊ฐ์ง ๊ธฐ๋ฅ๋ค์ ๋ ์ดํด๋ณด๊ฒ ์ต๋๋ค.
TensorBoard์ ๊ฐ์ ์ค ํ๋๋ ๋ณต์กํ ๋ชจ๋ธ ๊ตฌ์กฐ๋ฅผ ์๊ฐํํ๋ ๊ธฐ๋ฅ์ ๋๋ค. ์ง๊ธ๊น์ง ๋ง๋ ๋ชจ๋ธ์ ์๊ฐํํด๋ณด๊ฒ ์ต๋๋ค.
writer.add_graph(net, images)
writer.close()
TensorBoard๋ฅผ ์๋ก๊ณ ์นจ(refresh)ํ๋ฉด ์๋์ ๊ฐ์ด "Graphs" ํญ์ ๋ณผ ์ ์์ต๋๋ค:
์๋์์ "Net"์ ๋๋ธํด๋ฆญํ์ฌ ํผ์ณ๋ณด๋ฉด, ๋ชจ๋ธ์ ๊ตฌ์ฑํ๋ ๊ฐ๋ณ ์ฐ์ฐ(operation)๋ค์ ๋ํด ์์ธํ ๋ณผ ์ ์์ต๋๋ค.
TensorBoard๋ ์ด๋ฏธ์ง ๋ฐ์ดํฐ์ ๊ฐ์ ๊ณ ์ฐจ์ ๋ฐ์ดํฐ๋ฅผ ์ ์ฐจ์ ๊ณต๊ฐ์ ์๊ฐํํ๋๋ฐ ๋งค์ฐ ํธ๋ฆฌํ ๊ธฐ๋ฅ๋ค์ ์ ๊ณตํฉ๋๋ค; ์์ผ๋ก ์ด ๋ด์ฉ์ ์์๋ณด๊ฒ ์ต๋๋ค.
add_embedding ๋ฉ์๋(method)๋ฅผ ํตํด ๊ณ ์ฐจ์ ๋ฐ์ดํฐ์ ์ ์ฐจ์ ํํ(representation)์ ์๊ฐํํ ์ ์์ต๋๋ค.
# ํฌํผ(helper) ํจ์
def select_n_random(data, labels, n=100):
'''
๋ฐ์ดํฐ์
์์ n๊ฐ์ ์์์ ๋ฐ์ดํฐํฌ์ธํธ(datapoint)์ ๊ทธ์ ํด๋นํ๋ ๋ผ๋ฒจ์ ์ ํํฉ๋๋ค
'''
assert len(data) == len(labels)
perm = torch.randperm(len(data))
return data[perm][:n], labels[perm][:n]
# ์์์ ์ด๋ฏธ์ง๋ค๊ณผ ์ ๋ต(target) ์ธ๋ฑ์ค๋ฅผ ์ ํํฉ๋๋ค
images, labels = select_n_random(trainset.data, trainset.targets)
# ๊ฐ ์ด๋ฏธ์ง์ ๋ถ๋ฅ ๋ผ๋ฒจ(class label)์ ๊ฐ์ ธ์ต๋๋ค
class_labels = [classes[lab] for lab in labels]
# ์๋ฒ ๋ฉ(embedding) ๋ด์ญ์ ๊ธฐ๋กํฉ๋๋ค
features = images.view(-1, 28 * 28)
writer.add_embedding(features,
metadata=class_labels,
label_img=images.unsqueeze(1))
writer.close()
์ด์ TensorBoard์ "Projector" ํญ์์ - ๊ฐ๊ฐ์ 784 ์ฐจ์์ธ - 100๊ฐ์ ์ด๋ฏธ์ง๊ฐ 3์ฐจ์ ๊ณต๊ฐ์ ํฌ์ฌ(project)๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค. ๋ํ, ์ด๊ฒ์ ๋ํ์์ ๋๋ค: ํด๋ฆญํ๊ณ ๋๋๊ทธ(drag)ํ์ฌ 3์ฐจ์์ผ๋ก ํฌ์๋ ๊ฒ์ ํ์ ํ ์ ์์ต๋๋ค. ๋ง์ง๋ง์ผ๋ก ์๊ฐํ๋ฅผ ๋ ํธํ ๋ณผ ์ ์๋ ๋ช ๊ฐ์ง ํ์ด ์์ต๋๋ค: ์ข์ธก ์๋จ์์ "Color by: label"์ ์ ํํ๊ณ , "์ผ๊ฐ๋ชจ๋(night mode)"๋ฅผ ํ์ฑํํ๋ฉด ์ด๋ฏธ์ง ๋ฐฐ๊ฒฝ์ด ํฐ์์ด ๋์ด ๋ ํธํ๊ฒ ๋ณผ ์ ์์ต๋๋ค:
์ง๊ธ๊น์ง ๋ฐ์ดํฐ๋ฅผ ์ถฉ๋ถํ ์ดํด๋ณด์์ผ๋ฏ๋ก, ์ด์ ํ์ต ๊ณผ์ ๋ถํฐ ์์ํ์ฌ TensorBoard๊ฐ ์ด๋ป๊ฒ ๋ชจ๋ธ ํ์ต๊ณผ ํ๊ฐ(evaluation)๋ฅผ ๋ ๋ช ํํ ์ถ์ (track)ํ ์ ์๋์ง ์ดํด๋ณด๊ฒ ์ต๋๋ค.
์ด์ ์์ ์์๋ ๋จ์ํ ๋ชจ๋ธ ํ์ต ์ค ์์ค(running loss)์ 2000๋ฒ ๋ฐ๋ณตํ ๋๋ง๋ค
์ถ๋ ฅ ํ๊ธฐ๋ง ํ์ต๋๋ค. ์ด์ TensorBoard์ ํ์ต ์ค ์์ค์ ๊ธฐ๋กํ๋ ๊ฒ ๋์ ์
plot_classes_preds
ํจ์๋ฅผ ํตํด ๋ชจ๋ธ์ ์์ธก ๊ฒฐ๊ณผ๋ฅผ ํจ๊ป ๋ณผ ์ ์๋๋ก ํ๊ฒ ์ต๋๋ค.
# ํฌํผ ํจ์
def images_to_probs(net, images):
'''
ํ์ต๋ ์ ๊ฒฝ๋ง๊ณผ ์ด๋ฏธ์ง ๋ชฉ๋ก์ผ๋ก๋ถํฐ ์์ธก ๊ฒฐ๊ณผ ๋ฐ ํ๋ฅ ์ ์์ฑํฉ๋๋ค
'''
output = net(images)
# convert output probabilities to predicted class
_, preds_tensor = torch.max(output, 1)
preds = np.squeeze(preds_tensor.numpy())
return preds, [F.softmax(el, dim=0)[i].item() for i, el in zip(preds, output)]
def plot_classes_preds(net, images, labels):
'''
ํ์ต๋ ์ ๊ฒฝ๋ง๊ณผ ๋ฐฐ์น๋ก๋ถํฐ ๊ฐ์ ธ์จ ์ด๋ฏธ์ง / ๋ผ๋ฒจ์ ์ฌ์ฉํ์ฌ matplotlib
Figure๋ฅผ ์์ฑํฉ๋๋ค. ์ด๋ ์ ๊ฒฝ๋ง์ ์์ธก ๊ฒฐ๊ณผ / ํ๋ฅ ๊ณผ ํจ๊ป ์ ๋ต์ ๋ณด์ฌ์ฃผ๋ฉฐ,
์์ธก ๊ฒฐ๊ณผ๊ฐ ๋ง์๋์ง ์ฌ๋ถ์ ๋ฐ๋ผ ์์ ๋ค๋ฅด๊ฒ ํ์ํฉ๋๋ค. "images_to_probs"
ํจ์๋ฅผ ์ฌ์ฉํฉ๋๋ค.
'''
preds, probs = images_to_probs(net, images)
# ๋ฐฐ์น์์ ์ด๋ฏธ์ง๋ฅผ ๊ฐ์ ธ์ ์์ธก ๊ฒฐ๊ณผ / ์ ๋ต๊ณผ ํจ๊ป ํ์(plot)ํฉ๋๋ค
fig = plt.figure(figsize=(12, 48))
for idx in np.arange(4):
ax = fig.add_subplot(1, 4, idx+1, xticks=[], yticks=[])
matplotlib_imshow(images[idx], one_channel=True)
ax.set_title("{0}, {1:.1f}%\n(label: {2})".format(
classes[preds[idx]],
probs[idx] * 100.0,
classes[labels[idx]]),
color=("green" if preds[idx]==labels[idx].item() else "red"))
return fig
๋ง์ง๋ง์ผ๋ก, ์ด์ ํํ ๋ฆฌ์ผ๊ณผ ๋์ผํ ๋ชจ๋ธ ํ์ต ์ฝ๋์์ 1000 ๋ฐฐ์น๋ง๋ค ์ฝ์์ ์ถ๋ ฅํ๋ ๋์ ์ TensorBoard์ ๊ฒฐ๊ณผ๋ฅผ ๊ธฐ๋กํ๋๋ก ํ์ฌ ํ์ต์ ํด๋ณด๊ฒ ์ต๋๋ค; ์ด๋ add_scalar ํจ์๋ฅผ ์ฌ์ฉํฉ๋๋ค.
๋ํ, ํ์ต์ ์งํํ๋ฉด์ ๋ฐฐ์น์ ํฌํจ๋ 4๊ฐ์ ์ด๋ฏธ์ง์ ๋ํ ๋ชจ๋ธ์ ์์ธก ๊ฒฐ๊ณผ์ ์ ๋ต์ ๋น๊ต(versus)ํ์ฌ ๋ณด์ฌ์ฃผ๋ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋๋ก ํ๊ฒ ์ต๋๋ค.
running_loss = 0.0
for epoch in range(1): # ๋ฐ์ดํฐ์
์ ์ฌ๋ฌ๋ฒ ๋ฐ๋ณต
for i, data in enumerate(trainloader, 0):
# [inputs, labels]์ ๋ชฉ๋ก์ธ data๋ก๋ถํฐ ์
๋ ฅ์ ๋ฐ์ ํ;
inputs, labels = data
# ๋ณํ๋(Gradient) ๋งค๊ฐ๋ณ์๋ฅผ 0์ผ๋ก ๋ง๋ค๊ณ
optimizer.zero_grad()
# ์์ ํ + ์ญ์ ํ + ์ต์ ํ๋ฅผ ํ ํ
outputs = net(inputs)
loss = criterion(outputs, labels)
loss.backward()
optimizer.step()
running_loss += loss.item()
if i % 1000 == 999: # ๋งค 1000 ๋ฏธ๋๋ฐฐ์น๋ง๋ค...
# ...ํ์ต ์ค ์์ค(running loss)์ ๊ธฐ๋กํ๊ณ
writer.add_scalar('training loss',
running_loss / 1000,
epoch * len(trainloader) + i)
# ...๋ฌด์์ ๋ฏธ๋๋ฐฐ์น(mini-batch)์ ๋ํ ๋ชจ๋ธ์ ์์ธก ๊ฒฐ๊ณผ๋ฅผ ๋ณด์ฌ์ฃผ๋๋ก
# Matplotlib Figure๋ฅผ ๊ธฐ๋กํฉ๋๋ค
writer.add_figure('predictions vs. actuals',
plot_classes_preds(net, inputs, labels),
global_step=epoch * len(trainloader) + i)
running_loss = 0.0
print('Finished Training')
์ด์ 'Scalars' ํญ์์ 15,000๋ฒ ๋ฐ๋ณต ํ์ตํ ๋์ ์์ค์ ํ์ธํ ์ ์์ต๋๋ค:
๋ํ, ํ์ต ๊ณผ์ ์ ๋ฐ์ ๊ฑธ์ณ ์์์ ๋ฐฐ์น์ ๋ํ ๋ชจ๋ธ์ ์์ธก ๊ฒฐ๊ณผ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค. "Images" ํญ์์ ์คํฌ๋กค์ ๋ด๋ ค "์์ธก vs. ์ ๋ต(predictions vs. actuals)" ์๊ฐํ ๋ถ๋ถ์์ ์ด ๋ด์ฉ์ ๋ณผ ์ ์์ต๋๋ค; ์๋ฅผ ๋ค์ด ํ์ต์ ๋จ์ง 3000๋ฒ ๋ฐ๋ณตํ๊ธฐ๋ง ํด๋, ์ ๋ขฐ๋๋ ๋์ง ์์ง๋ง, ๋ชจ๋ธ์ ์ ์ธ ์ ์ด๋ํ(sneakers), ์ฝํธ์ ๊ฐ์ ๋ถ๋ฅ๋ค์ ๊ตฌ๋ถํ ์ ์์์ต๋๋ค:
์ด์ ํํ ๋ฆฌ์ผ์์๋ ๋ชจ๋ธ์ด ํ์ต ์๋ฃ๋ ํ์ ๊ฐ ๋ถ๋ฅ๋ณ ์ ํ๋(per-class accuracy)๋ฅผ ์ดํด๋ดค์ต๋๋ค; ์ฌ๊ธฐ์๋ TensorBoard๋ฅผ ์ฌ์ฉํ์ฌ ๊ฐ ๋ถ๋ฅ๋ณ ์ ๋ฐ๋-์ฌํ์จ(precision-recall) ๊ณก์ ( ์ฌ๊ธฐ ์ ์ข์ ์ค๋ช ์ด ์์ต๋๋ค)์ ๊ทธ๋ ค๋ณด๊ฒ ์ต๋๋ค.
# 1. ์์ธก ํ๋ฅ ์ test_size x num_classes ํ
์๋ก ๊ฐ์ ธ์ต๋๋ค
# 2. ์์ธก ๊ฒฐ๊ณผ๋ฅผ test_size ํ
์๋ก ๊ฐ์ ธ์ต๋๋ค
# ์คํํ๋๋ฐ 10์ด ์ดํ ์์
class_probs = []
class_label = []
with torch.no_grad():
for data in testloader:
images, labels = data
output = net(images)
class_probs_batch = [F.softmax(el, dim=0) for el in output]
class_probs.append(class_probs_batch)
class_label.append(labels)
test_probs = torch.cat([torch.stack(batch) for batch in class_probs])
test_label = torch.cat(class_label)
# ํฌํผ ํจ์
def add_pr_curve_tensorboard(class_index, test_probs, test_label, global_step=0):
'''
0๋ถํฐ 9๊น์ง์ "class_index"๋ฅผ ๊ฐ์ ธ์จ ํ ํด๋น ์ ๋ฐ๋-์ฌํ์จ(precision-recall)
๊ณก์ ์ ๊ทธ๋ฆฝ๋๋ค
'''
tensorboard_truth = test_label == class_index
tensorboard_probs = test_probs[:, class_index]
writer.add_pr_curve(classes[class_index],
tensorboard_truth,
tensorboard_probs,
global_step=global_step)
writer.close()
# ๋ชจ๋ ์ ๋ฐ๋-์ฌํ์จ(precision-recall; pr) ๊ณก์ ์ ๊ทธ๋ฆฝ๋๋ค
for i in range(len(classes)):
add_pr_curve_tensorboard(i, test_probs, test_preds)
์ด์ "PR Curves" ํญ์์ ๊ฐ ๋ถ๋ฅ๋ณ ์ ๋ฐ๋-์ฌํ์จ ๊ณก์ ์ ๋ณผ ์ ์์ต๋๋ค. ๋ด๋ ค๋ณด๋ฉด์ ์ดํด๋ณด์ญ์์ค; ์ผ๋ถ ๋ถ๋ฅ๋ ๊ฑฐ์ 100%์ "์์ญ์ด ๊ณก์ ์๋"์ ์๊ณ , ๋ค๋ฅธ ๋ถ๋ฅ๋ค์ ์ด ์์ญ์ด ๋ ์ ์ต๋๋ค:
์ฌ๊ธฐ๊น์ง TensorBoard์ PyTorch์ ํตํฉ์ ๋ํด ์๊ฐํ์ต๋๋ค. ๋ฌผ๋ก TensorBoard์์ ์ ๊ณตํ๋ ๋ชจ๋ ๊ฒ๋ค์ Jupyter Notebook์์๋ ํ ์ ์์ง๋ง, TensorBoard๋ฅผ ์ฌ์ฉํ๋ฉด ๋ํํ ์๊ฐํ๊ฐ ๊ธฐ๋ณธ์ผ๋ก ์ ๊ณต๋ฉ๋๋ค.