René's URL Explorer Experiment


Title: TensorBoard로 모델, 데이터, 학습 시각화하기 — 파이토치 한국어 튜토리얼 (PyTorch tutorials in Korean)

Open Graph Title: TensorBoard로 모델, 데이터, 학습 시각화하기

Description: PyTorch로 딥러닝하기: 60분만에 끝장내기 에서는 데이터를 불러오고, nn.Module 의 서브클래스(subclass)로 정의한 모델에 데이터를 공급(feed)하고, 학습 데이터로 모델을 학습하고 테스트 데이터로 테스트를 하는 방법들을 살펴봤습니다. 진행 상황을 살펴보기 위해, 학습이 진행 중일 때 학습이 잘 되고 있는지를 알아보기 위해 몇몇 수치들(statistic)을 출력했습니다. 하지만 더 나은 방법도 있습니다: PyTorch는 신경망 학습 내역을 시각화하는 도구인 TensorBoard와 통합되었습니다. 이 튜토리얼...

Open Graph Description: PyTorch로 딥러닝하기: 60분만에 끝장내기 에서는 데이터를 불러오고, nn.Module 의 서브클래스(subclass)로 정의한 모델에 데이터를 공급(feed)하고, 학습 데이터로 모델을 학습하고 테스트 데이터로 테스트를 하는 방법들을 살펴봤습니다. 진행 상황을 살펴보기 위해, 학습이 진행 중일 때 학습이 잘 되고 있는지를 알아보기 위해 몇몇 수치들(statistic)을 출력했습니다. 하지만 더 나은 방법도 있습니다: PyTorch는 신경망 학습 내역을 시각화하는 도구인 TensorBoard와 통합되었습니다. 이 튜토리얼...

Opengraph URL: https://tutorials.pytorch.kr/intermediate/tensorboard_tutorial.html

direct link

Domain: tutorials.pytorch.kr


Hey, it has json ld scripts:
    {
       "@context": "https://schema.org",
       "@type": "Article",
       "name": "TensorBoard\ub85c \ubaa8\ub378, \ub370\uc774\ud130, \ud559\uc2b5 \uc2dc\uac01\ud654\ud558\uae30",
       "headline": "TensorBoard\ub85c \ubaa8\ub378, \ub370\uc774\ud130, \ud559\uc2b5 \uc2dc\uac01\ud654\ud558\uae30",
       "description": "PyTorch Documentation. Explore PyTorch, an open-source machine learning library that accelerates the path from research prototyping to production deployment. Discover tutorials, API references, and guides to help you build and deploy deep learning models efficiently.",
       "url": "/intermediate/tensorboard_tutorial.html",
       "articleBody": "TensorBoard\ub85c \ubaa8\ub378, \ub370\uc774\ud130, \ud559\uc2b5 \uc2dc\uac01\ud654\ud558\uae30# PyTorch\ub85c \ub525\ub7ec\ub2dd\ud558\uae30: 60\ubd84\ub9cc\uc5d0 \ub05d\uc7a5\ub0b4\uae30 \uc5d0\uc11c\ub294 \ub370\uc774\ud130\ub97c \ubd88\ub7ec\uc624\uace0, nn.Module \uc758 \uc11c\ube0c\ud074\ub798\uc2a4(subclass)\ub85c \uc815\uc758\ud55c \ubaa8\ub378\uc5d0 \ub370\uc774\ud130\ub97c \uacf5\uae09(feed)\ud558\uace0, \ud559\uc2b5 \ub370\uc774\ud130\ub85c \ubaa8\ub378\uc744 \ud559\uc2b5\ud558\uace0 \ud14c\uc2a4\ud2b8 \ub370\uc774\ud130\ub85c \ud14c\uc2a4\ud2b8\ub97c \ud558\ub294 \ubc29\ubc95\ub4e4\uc744 \uc0b4\ud3b4\ubd24\uc2b5\ub2c8\ub2e4. \uc9c4\ud589 \uc0c1\ud669\uc744 \uc0b4\ud3b4\ubcf4\uae30 \uc704\ud574, \ud559\uc2b5\uc774 \uc9c4\ud589 \uc911\uc77c \ub54c \ud559\uc2b5\uc774 \uc798 \ub418\uace0 \uc788\ub294\uc9c0\ub97c \uc54c\uc544\ubcf4\uae30 \uc704\ud574 \uba87\uba87 \uc218\uce58\ub4e4(statistic)\uc744 \ucd9c\ub825\ud588\uc2b5\ub2c8\ub2e4. \ud558\uc9c0\ub9cc \ub354 \ub098\uc740 \ubc29\ubc95\ub3c4 \uc788\uc2b5\ub2c8\ub2e4: PyTorch\ub294 \uc2e0\uacbd\ub9dd \ud559\uc2b5 \ub0b4\uc5ed\uc744 \uc2dc\uac01\ud654\ud558\ub294 \ub3c4\uad6c\uc778 TensorBoard\uc640 \ud1b5\ud569\ub418\uc5c8\uc2b5\ub2c8\ub2e4. \uc774 \ud29c\ud1a0\ub9ac\uc5bc\uc5d0\uc11c\ub294 PyTorch\uc758 torchvision.datasets \uc5d0\uc11c \uc0ac\uc6a9 \uac00\ub2a5\ud55c Fashion-MNIST dataset \uc73c\ub85c \uc77c\ubd80 \uae30\ub2a5\uc744 \uc124\uba85\ud558\uaca0\uc2b5\ub2c8\ub2e4. \uc774 \ud29c\ud1a0\ub9ac\uc5bc\uc5d0\uc11c\ub294 \ub2e4\uc74c\uc758 \ub0b4\uc6a9\ub4e4\uc744 \ubc30\uc6c1\ub2c8\ub2e4: (\uc774\uc804 \ud29c\ud1a0\ub9ac\uc5bc\uacfc \uac70\uc758 \ube44\uc2b7\ud558\uac8c) \ub370\uc774\ud130\ub97c \uc77d\uace0 \uc801\uc808\ud788 \ubcc0\ud658\ud569\ub2c8\ub2e4. TensorBoard\ub97c \uc124\uc815(set up)\ud569\ub2c8\ub2e4. TensorBoard\uc5d0 \uae30\ub85d(write)\ud569\ub2c8\ub2e4. TensorBoard\ub97c \uc0ac\uc6a9\ud558\uc5ec \ubaa8\ub378 \uad6c\uc870\ub97c \uc0b4\ud3b4\ubd05\ub2c8\ub2e4. \uc57d\uac04\uc758 \ucf54\ub4dc\ub97c \ucd94\uac00\ud558\uc5ec TensorBoard\uc5d0\uc11c \uc774\uc804 \ud29c\ud1a0\ub9ac\uc5bc\uc5d0\uc11c \ub9cc\ub4e0 \uc2dc\uac01\ud654\uc758 \ub300\ud654\uc2dd(interactive) \ubc84\uc804\uc744 \ub9cc\ub4ed\ub2c8\ub2e4. \uad6c\uccb4\uc801\uc73c\ub85c #5\uc5d0\uc11c\ub294 \ub2e4\uc74c \ub0b4\uc6a9\ub4e4\uc744 \uc0b4\ud3b4\ubcf4\ub3c4\ub85d \ud558\uaca0\uc2b5\ub2c8\ub2e4: \ud559\uc2b5 \ub370\uc774\ud130\ub97c \uac80\uc0ac(inspect)\ud558\ub294 \uba87 \uac00\uc9c0 \ubc29\ubc95 \ud559\uc2b5\uc5d0 \ub530\ub978 \ubaa8\ub378\uc758 \uc131\ub2a5\uc744 \ucd94\uc801(track)\ud558\ub294 \ubc29\ubc95 \ud559\uc2b5\uc774 \uc644\ub8cc\ub41c \ubaa8\ub378\uc758 \uc131\ub2a5\uc744 \ud3c9\uac00(assess)\ud558\ub294 \ubc29\ubc95 \ubd84\ub958\uae30(Classifier) \ud559\uc2b5\ud558\uae30 \uc640 \ube44\uc2b7\ud55c \ucf54\ub4dc\ub85c \uc2dc\uc791\ud574\ubcf4\uaca0\uc2b5\ub2c8\ub2e4: # 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(\u0027./data\u0027, download=True, train=True, transform=transform) testset = torchvision.datasets.FashionMNIST(\u0027./data\u0027, download=True, train=False, transform=transform) # dataloaders trainloader = torch.utils.data.DataLoader(trainset, batch_size=4, shuffle=True) testloader = torch.utils.data.DataLoader(testset, batch_size=4, shuffle=False) # \ubd84\ub958 \uacb0\uacfc\ub97c \uc704\ud55c \uc0c1\uc218 classes = (\u0027T-shirt/top\u0027, \u0027Trouser\u0027, \u0027Pullover\u0027, \u0027Dress\u0027, \u0027Coat\u0027, \u0027Sandal\u0027, \u0027Shirt\u0027, \u0027Sneaker\u0027, \u0027Bag\u0027, \u0027Ankle Boot\u0027) # \uc774\ubbf8\uc9c0\ub97c \ubcf4\uc5ec\uc8fc\uae30 \uc704\ud55c \ud5ec\ud37c(helper) \ud568\uc218 # (\uc544\ub798 `plot_classes_preds` \ud568\uc218\uc5d0\uc11c \uc0ac\uc6a9) 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))) \uc774\uc804 \ud29c\ud1a0\ub9ac\uc5bc\uacfc \uc720\uc0ac\ud55c \ubaa8\ub378 \uad6c\uc870\ub97c \uc815\uc758\ud558\ub418, \uc774\ubbf8\uc9c0\uc758 \ucc44\ub110\uc774 3\uac1c\uc5d0\uc11c 1\uac1c\ub85c, \ud06c\uae30\uac00 32x32\uc5d0\uc11c 28x28\ub85c \ubcc0\uacbd\ub41c \uac83\uc744 \uc801\uc6a9\ud560 \uc218 \uc788\ub3c4\ub85d \uc57d\uac04\ub9cc \uc218\uc815\ud558\uaca0\uc2b5\ub2c8\ub2e4: 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() \ub3d9\uc77c\ud55c optimizer \uc640 criterion \uc744 \uc815\uc758\ud569\ub2c8\ub2e4: criterion = nn.CrossEntropyLoss() optimizer = optim.SGD(net.parameters(), lr=0.001, momentum=0.9) 1. TensorBoard \uc124\uc815# \uc774\uc81c torch.utils \uc758 tensorboard \ub97c \ubd88\ub7ec\uc624\uace0, TensorBoard\uc5d0 \uc815\ubcf4\ub97c \uc81c\uacf5(write)\ud558\ub294 SummaryWriter \ub97c \uc8fc\uc694\ud55c \uac1d\uccb4\uc778 SummaryWriter \ub97c \uc815\uc758\ud558\uc5ec TensorBoard\ub97c \uc124\uc815\ud569\ub2c8\ub2e4. from torch.utils.tensorboard import SummaryWriter # \uae30\ubcf8 `log_dir` \uc740 \"runs\"\uc774\uba70, \uc5ec\uae30\uc11c\ub294 \ub354 \uad6c\uccb4\uc801\uc73c\ub85c \uc9c0\uc815\ud558\uc600\uc2b5\ub2c8\ub2e4 writer = SummaryWriter(\u0027runs/fashion_mnist_experiment_1\u0027) \uc704 \ud589(line)\uc740 runs/fashion_mnist_experiment_1 \ud3f4\ub354\ub97c \uc0dd\uc131\ud569\ub2c8\ub2e4. 2. TensorBoard\uc5d0 \uae30\ub85d\ud558\uae30# \uc774\uc81c TensorBoard\uc5d0 \uc774\ubbf8\uc9c0(\uad6c\uccb4\uc801\uc73c\ub85c\ub294 make_grid \ub97c \uc0ac\uc6a9\ud558\uc5ec \uadf8\ub9ac\ub4dc(grid))\ub97c \uc368\ubcf4\uaca0\uc2b5\ub2c8\ub2e4. # \uc784\uc758\uc758 \ud559\uc2b5 \uc774\ubbf8\uc9c0\ub97c \uac00\uc838\uc635\ub2c8\ub2e4 dataiter = iter(trainloader) images, labels = next(dataiter) # \uc774\ubbf8\uc9c0 \uadf8\ub9ac\ub4dc\ub97c \ub9cc\ub4ed\ub2c8\ub2e4. img_grid = torchvision.utils.make_grid(images) # \uc774\ubbf8\uc9c0\ub97c \ubcf4\uc5ec\uc90d\ub2c8\ub2e4. matplotlib_imshow(img_grid, one_channel=True) # tensorboard\uc5d0 \uae30\ub85d\ud569\ub2c8\ub2e4. writer.add_image(\u0027four_fashion_mnist_images\u0027, img_grid) \uc774\uc81c \uba85\ub839\uc904(command line)\uc5d0\uc11c PYTHONWARNINGS=\"ignore:pkg_resources is deprecated as an API:UserWarning\" tensorboard --logdir=runs \ub97c \uc2e4\ud589\ud558\uace0, http://localhost:6006 \uc744 \uc5f4\uc5b4\ubcf4\uba74 \ub2e4\uc74c\uacfc \uac19\uc740 \ud654\uba74\uc774 \ub098\ud0c0\ub0a9\ub2c8\ub2e4. \uc9c0\uae08\uae4c\uc9c0 TensorBoard\ub97c \uc5b4\ub5bb\uac8c \uc0ac\uc6a9\ud558\ub294\uc9c0\ub97c \uc54c\uc544\ubcf4\uc558\uc2b5\ub2c8\ub2e4! \uadf8\ub7ec\ub098, \uc774 \uc608\uc81c\ub294 Jupyter Notebook\uc5d0\uc11c\ub3c4 \uac00\ub2a5\ud569\ub2c8\ub2e4 - TensorBoard\ub294 \ub300\ud654\ud615 \uc2dc\uac01\ud654\ub97c \ub9cc\ub4dc\ub294\ub370 \ud2b9\ud788 \ub6f0\uc5b4\ub0a9\ub2c8\ub2e4. \ub2e4\uc74c\uc5d0 \uadf8\ub7f0 \uae30\ub2a5\ub4e4 \uc911 \ud558\ub098\ub97c \uc0b4\ud3b4\ubcf4\uace0, \ud29c\ud1a0\ub9ac\uc5bc\uc758 \ub098\uba38\uc9c0 \ubd80\ubd84\uc5d0\uc11c \uba87 \uac00\uc9c0 \uae30\ub2a5\ub4e4\uc744 \ub354 \uc0b4\ud3b4\ubcf4\uaca0\uc2b5\ub2c8\ub2e4. 3. TensorBoard\ub97c \uc0ac\uc6a9\ud558\uc5ec \ubaa8\ub378 \uc0b4\ud3b4\ubcf4\uae30(inspect)# TensorBoard\uc758 \uac15\uc810 \uc911 \ud558\ub098\ub294 \ubcf5\uc7a1\ud55c \ubaa8\ub378 \uad6c\uc870\ub97c \uc2dc\uac01\ud654\ud558\ub294 \uae30\ub2a5\uc785\ub2c8\ub2e4. \uc9c0\uae08\uae4c\uc9c0 \ub9cc\ub4e0 \ubaa8\ub378\uc744 \uc2dc\uac01\ud654\ud574\ubcf4\uaca0\uc2b5\ub2c8\ub2e4. writer.add_graph(net, images) writer.close() TensorBoard\ub97c \uc0c8\ub85c\uace0\uce68(refresh)\ud558\uba74 \uc544\ub798\uc640 \uac19\uc774 \u201cGraphs\u201d \ud0ed\uc744 \ubcfc \uc218 \uc788\uc2b5\ub2c8\ub2e4: \uc544\ub798\uc5d0\uc11c \u201cNet\u201d\uc744 \ub354\ube14\ud074\ub9ad\ud558\uc5ec \ud3bc\uccd0\ubcf4\uba74, \ubaa8\ub378\uc744 \uad6c\uc131\ud558\ub294 \uac1c\ubcc4 \uc5f0\uc0b0(operation)\ub4e4\uc5d0 \ub300\ud574 \uc790\uc138\ud788 \ubcfc \uc218 \uc788\uc2b5\ub2c8\ub2e4. TensorBoard\ub294 \uc774\ubbf8\uc9c0 \ub370\uc774\ud130\uc640 \uac19\uc740 \uace0\ucc28\uc6d0 \ub370\uc774\ud130\ub97c \uc800\ucc28\uc6d0 \uacf5\uac04\uc5d0 \uc2dc\uac01\ud654\ud558\ub294\ub370 \ub9e4\uc6b0 \ud3b8\ub9ac\ud55c \uae30\ub2a5\ub4e4\uc744 \uc81c\uacf5\ud569\ub2c8\ub2e4; \uc55e\uc73c\ub85c \uc774 \ub0b4\uc6a9\uc744 \uc54c\uc544\ubcf4\uaca0\uc2b5\ub2c8\ub2e4. 4. TensorBoard\uc5d0 \u201cProjector\u201d \ucd94\uac00\ud558\uae30# add_embedding \uba54\uc18c\ub4dc(method)\ub97c \ud1b5\ud574 \uace0\ucc28\uc6d0 \ub370\uc774\ud130\uc758 \uc800\ucc28\uc6d0 \ud45c\ud604(representation)\uc744 \uc2dc\uac01\ud654\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. # \ud5ec\ud37c(helper) \ud568\uc218 def select_n_random(data, labels, n=100): \u0027\u0027\u0027 \ub370\uc774\ud130\uc14b\uc5d0\uc11c n\uac1c\uc758 \uc784\uc758\uc758 \ub370\uc774\ud130\ud3ec\uc778\ud2b8(datapoint)\uc640 \uadf8\uc5d0 \ud574\ub2f9\ud558\ub294 \ub77c\ubca8\uc744 \uc120\ud0dd\ud569\ub2c8\ub2e4 \u0027\u0027\u0027 assert len(data) == len(labels) perm = torch.randperm(len(data)) return data[perm][:n], labels[perm][:n] # \uc784\uc758\uc758 \uc774\ubbf8\uc9c0\ub4e4\uacfc \uc815\ub2f5(target) \uc778\ub371\uc2a4\ub97c \uc120\ud0dd\ud569\ub2c8\ub2e4 images, labels = select_n_random(trainset.data, trainset.targets) # \uac01 \uc774\ubbf8\uc9c0\uc758 \ubd84\ub958 \ub77c\ubca8(class label)\uc744 \uac00\uc838\uc635\ub2c8\ub2e4 class_labels = [classes[lab] for lab in labels] # \uc784\ubca0\ub529(embedding) \ub0b4\uc5ed\uc744 \uae30\ub85d\ud569\ub2c8\ub2e4 features = images.view(-1, 28 * 28) writer.add_embedding(features, metadata=class_labels, label_img=images.unsqueeze(1)) writer.close() \uc774\uc81c TensorBoard\uc758 \u201cProjector\u201d \ud0ed\uc5d0\uc11c - \uac01\uac01\uc740 784 \ucc28\uc6d0\uc778 - 100\uac1c\uc758 \uc774\ubbf8\uc9c0\uac00 3\ucc28\uc6d0 \uacf5\uac04\uc5d0 \ud22c\uc0ac(project)\ub41c \uac83\uc744 \ubcfc \uc218 \uc788\uc2b5\ub2c8\ub2e4. \ub610\ud55c, \uc774\uac83\uc740 \ub300\ud654\uc2dd\uc785\ub2c8\ub2e4: \ud074\ub9ad\ud558\uace0 \ub4dc\ub798\uadf8(drag)\ud558\uc5ec 3\ucc28\uc6d0\uc73c\ub85c \ud22c\uc601\ub41c \uac83\uc744 \ud68c\uc804\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \ub9c8\uc9c0\ub9c9\uc73c\ub85c \uc2dc\uac01\ud654\ub97c \ub354 \ud3b8\ud788 \ubcfc \uc218 \uc788\ub294 \uba87 \uac00\uc9c0 \ud301\uc774 \uc788\uc2b5\ub2c8\ub2e4: \uc88c\uce21 \uc0c1\ub2e8\uc5d0\uc11c \u201cColor by: label\u201d\uc744 \uc120\ud0dd\ud558\uace0, \u201c\uc57c\uac04\ubaa8\ub4dc(night mode)\u201d\ub97c \ud65c\uc131\ud654\ud558\uba74 \uc774\ubbf8\uc9c0 \ubc30\uacbd\uc774 \ud770\uc0c9\uc774 \ub418\uc5b4 \ub354 \ud3b8\ud558\uac8c \ubcfc \uc218 \uc788\uc2b5\ub2c8\ub2e4: \uc9c0\uae08\uae4c\uc9c0 \ub370\uc774\ud130\ub97c \ucda9\ubd84\ud788 \uc0b4\ud3b4\ubcf4\uc558\uc73c\ubbc0\ub85c, \uc774\uc81c \ud559\uc2b5 \uacfc\uc815\ubd80\ud130 \uc2dc\uc791\ud558\uc5ec TensorBoard\uac00 \uc5b4\ub5bb\uac8c \ubaa8\ub378 \ud559\uc2b5\uacfc \ud3c9\uac00(evaluation)\ub97c \ub354 \uba85\ud655\ud788 \ucd94\uc801(track)\ud560 \uc218 \uc788\ub294\uc9c0 \uc0b4\ud3b4\ubcf4\uaca0\uc2b5\ub2c8\ub2e4. 5. TensorBoard\ub85c \ubaa8\ub378 \ud559\uc2b5 \ucd94\uc801\ud558\uae30# \uc774\uc804 \uc608\uc81c\uc5d0\uc11c\ub294 \ub2e8\uc21c\ud788 \ubaa8\ub378 \ud559\uc2b5 \uc911 \uc190\uc2e4(running loss)\uc744 2000\ubc88 \ubc18\ubcf5\ud560 \ub54c\ub9c8\ub2e4 \ucd9c\ub825 \ud558\uae30\ub9cc \ud588\uc2b5\ub2c8\ub2e4. \uc774\uc81c TensorBoard\uc5d0 \ud559\uc2b5 \uc911 \uc190\uc2e4\uc744 \uae30\ub85d\ud558\ub294 \uac83 \ub300\uc2e0\uc5d0 plot_classes_preds \ud568\uc218\ub97c \ud1b5\ud574 \ubaa8\ub378\uc758 \uc608\uce21 \uacb0\uacfc\ub97c \ud568\uaed8 \ubcfc \uc218 \uc788\ub3c4\ub85d \ud558\uaca0\uc2b5\ub2c8\ub2e4. # \ud5ec\ud37c \ud568\uc218 def images_to_probs(net, images): \u0027\u0027\u0027 \ud559\uc2b5\ub41c \uc2e0\uacbd\ub9dd\uacfc \uc774\ubbf8\uc9c0 \ubaa9\ub85d\uc73c\ub85c\ubd80\ud130 \uc608\uce21 \uacb0\uacfc \ubc0f \ud655\ub960\uc744 \uc0dd\uc131\ud569\ub2c8\ub2e4 \u0027\u0027\u0027 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): \u0027\u0027\u0027 \ud559\uc2b5\ub41c \uc2e0\uacbd\ub9dd\uacfc \ubc30\uce58\ub85c\ubd80\ud130 \uac00\uc838\uc628 \uc774\ubbf8\uc9c0 / \ub77c\ubca8\uc744 \uc0ac\uc6a9\ud558\uc5ec matplotlib Figure\ub97c \uc0dd\uc131\ud569\ub2c8\ub2e4. \uc774\ub294 \uc2e0\uacbd\ub9dd\uc758 \uc608\uce21 \uacb0\uacfc / \ud655\ub960\uacfc \ud568\uaed8 \uc815\ub2f5\uc744 \ubcf4\uc5ec\uc8fc\uba70, \uc608\uce21 \uacb0\uacfc\uac00 \ub9de\uc558\ub294\uc9c0 \uc5ec\ubd80\uc5d0 \ub530\ub77c \uc0c9\uc744 \ub2e4\ub974\uac8c \ud45c\uc2dc\ud569\ub2c8\ub2e4. \"images_to_probs\" \ud568\uc218\ub97c \uc0ac\uc6a9\ud569\ub2c8\ub2e4. \u0027\u0027\u0027 preds, probs = images_to_probs(net, images) # \ubc30\uce58\uc5d0\uc11c \uc774\ubbf8\uc9c0\ub97c \uac00\uc838\uc640 \uc608\uce21 \uacb0\uacfc / \uc815\ub2f5\uacfc \ud568\uaed8 \ud45c\uc2dc(plot)\ud569\ub2c8\ub2e4 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 \ub9c8\uc9c0\ub9c9\uc73c\ub85c, \uc774\uc804 \ud29c\ud1a0\ub9ac\uc5bc\uacfc \ub3d9\uc77c\ud55c \ubaa8\ub378 \ud559\uc2b5 \ucf54\ub4dc\uc5d0\uc11c 1000 \ubc30\uce58\ub9c8\ub2e4 \ucf58\uc194\uc5d0 \ucd9c\ub825\ud558\ub294 \ub300\uc2e0\uc5d0 TensorBoard\uc5d0 \uacb0\uacfc\ub97c \uae30\ub85d\ud558\ub3c4\ub85d \ud558\uc5ec \ud559\uc2b5\uc744 \ud574\ubcf4\uaca0\uc2b5\ub2c8\ub2e4; \uc774\ub294 add_scalar \ud568\uc218\ub97c \uc0ac\uc6a9\ud569\ub2c8\ub2e4. \ub610\ud55c, \ud559\uc2b5\uc744 \uc9c4\ud589\ud558\uba74\uc11c \ubc30\uce58\uc5d0 \ud3ec\ud568\ub41c 4\uac1c\uc758 \uc774\ubbf8\uc9c0\uc5d0 \ub300\ud55c \ubaa8\ub378\uc758 \uc608\uce21 \uacb0\uacfc\uc640 \uc815\ub2f5\uc744 \ube44\uad50(versus)\ud558\uc5ec \ubcf4\uc5ec\uc8fc\ub294 \uc774\ubbf8\uc9c0\ub97c \uc0dd\uc131\ud558\ub3c4\ub85d \ud558\uaca0\uc2b5\ub2c8\ub2e4. running_loss = 0.0 for epoch in range(1): # \ub370\uc774\ud130\uc14b\uc744 \uc5ec\ub7ec\ubc88 \ubc18\ubcf5 for i, data in enumerate(trainloader, 0): # [inputs, labels]\uc758 \ubaa9\ub85d\uc778 data\ub85c\ubd80\ud130 \uc785\ub825\uc744 \ubc1b\uc740 \ud6c4; inputs, labels = data # \ubcc0\ud654\ub3c4(Gradient) \ub9e4\uac1c\ubcc0\uc218\ub97c 0\uc73c\ub85c \ub9cc\ub4e4\uace0 optimizer.zero_grad() # \uc21c\uc804\ud30c + \uc5ed\uc804\ud30c + \ucd5c\uc801\ud654\ub97c \ud55c \ud6c4 outputs = net(inputs) loss = criterion(outputs, labels) loss.backward() optimizer.step() running_loss += loss.item() if i % 1000 == 999: # \ub9e4 1000 \ubbf8\ub2c8\ubc30\uce58\ub9c8\ub2e4... # ...\ud559\uc2b5 \uc911 \uc190\uc2e4(running loss)\uc744 \uae30\ub85d\ud558\uace0 writer.add_scalar(\u0027training loss\u0027, running_loss / 1000, epoch * len(trainloader) + i) # ...\ubb34\uc791\uc704 \ubbf8\ub2c8\ubc30\uce58(mini-batch)\uc5d0 \ub300\ud55c \ubaa8\ub378\uc758 \uc608\uce21 \uacb0\uacfc\ub97c \ubcf4\uc5ec\uc8fc\ub3c4\ub85d # Matplotlib Figure\ub97c \uae30\ub85d\ud569\ub2c8\ub2e4 writer.add_figure(\u0027predictions vs. actuals\u0027, plot_classes_preds(net, inputs, labels), global_step=epoch * len(trainloader) + i) running_loss = 0.0 print(\u0027Finished Training\u0027) \uc774\uc81c \u2018Scalars\u2019 \ud0ed\uc5d0\uc11c 15,000\ubc88 \ubc18\ubcf5 \ud559\uc2b5\ud560 \ub54c\uc758 \uc190\uc2e4\uc744 \ud655\uc778\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4: \ub610\ud55c, \ud559\uc2b5 \uacfc\uc815 \uc804\ubc18\uc5d0 \uac78\uccd0 \uc784\uc758\uc758 \ubc30\uce58\uc5d0 \ub300\ud55c \ubaa8\ub378\uc758 \uc608\uce21 \uacb0\uacfc\ub97c \ud655\uc778\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \u201cImages\u201d \ud0ed\uc5d0\uc11c \uc2a4\ud06c\ub864\uc744 \ub0b4\ub824 \u201c\uc608\uce21 vs. \uc815\ub2f5(predictions vs. actuals)\u201d \uc2dc\uac01\ud654 \ubd80\ubd84\uc5d0\uc11c \uc774 \ub0b4\uc6a9\uc744 \ubcfc \uc218 \uc788\uc2b5\ub2c8\ub2e4; \uc608\ub97c \ub4e4\uc5b4 \ud559\uc2b5\uc744 \ub2e8\uc9c0 3000\ubc88 \ubc18\ubcf5\ud558\uae30\ub9cc \ud574\ub3c4, \uc2e0\ub8b0\ub3c4\ub294 \ub192\uc9c4 \uc54a\uc9c0\ub9cc, \ubaa8\ub378\uc740 \uc154\uce20\uc640 \uc6b4\ub3d9\ud654(sneakers), \ucf54\ud2b8\uc640 \uac19\uc740 \ubd84\ub958\ub4e4\uc744 \uad6c\ubd84\ud560 \uc218 \uc788\uc5c8\uc2b5\ub2c8\ub2e4: \uc774\uc804 \ud29c\ud1a0\ub9ac\uc5bc\uc5d0\uc11c\ub294 \ubaa8\ub378\uc774 \ud559\uc2b5 \uc644\ub8cc\ub41c \ud6c4\uc5d0 \uac01 \ubd84\ub958\ubcc4 \uc815\ud655\ub3c4(per-class accuracy)\ub97c \uc0b4\ud3b4\ubd24\uc2b5\ub2c8\ub2e4; \uc5ec\uae30\uc11c\ub294 TensorBoard\ub97c \uc0ac\uc6a9\ud558\uc5ec \uac01 \ubd84\ub958\ubcc4 \uc815\ubc00\ub3c4-\uc7ac\ud604\uc728(precision-recall) \uace1\uc120( \uc5ec\uae30 \uc5d0 \uc88b\uc740 \uc124\uba85\uc774 \uc788\uc2b5\ub2c8\ub2e4)\uc744 \uadf8\ub824\ubcf4\uaca0\uc2b5\ub2c8\ub2e4. 6. TensorBoard\ub85c \ud559\uc2b5\ub41c \ubaa8\ub378 \ud3c9\uac00\ud558\uae30# # 1. \uc608\uce21 \ud655\ub960\uc744 test_size x num_classes \ud150\uc11c\ub85c \uac00\uc838\uc635\ub2c8\ub2e4 # 2. \uc608\uce21 \uacb0\uacfc\ub97c test_size \ud150\uc11c\ub85c \uac00\uc838\uc635\ub2c8\ub2e4 # \uc2e4\ud589\ud558\ub294\ub370 10\ucd08 \uc774\ud558 \uc18c\uc694 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) # \ud5ec\ud37c \ud568\uc218 def add_pr_curve_tensorboard(class_index, test_probs, test_label, global_step=0): \u0027\u0027\u0027 0\ubd80\ud130 9\uae4c\uc9c0\uc758 \"class_index\"\ub97c \uac00\uc838\uc628 \ud6c4 \ud574\ub2f9 \uc815\ubc00\ub3c4-\uc7ac\ud604\uc728(precision-recall) \uace1\uc120\uc744 \uadf8\ub9bd\ub2c8\ub2e4 \u0027\u0027\u0027 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() # \ubaa8\ub4e0 \uc815\ubc00\ub3c4-\uc7ac\ud604\uc728(precision-recall; pr) \uace1\uc120\uc744 \uadf8\ub9bd\ub2c8\ub2e4 for i in range(len(classes)): add_pr_curve_tensorboard(i, test_probs, test_preds) \uc774\uc81c \u201cPR Curves\u201d \ud0ed\uc5d0\uc11c \uac01 \ubd84\ub958\ubcc4 \uc815\ubc00\ub3c4-\uc7ac\ud604\uc728 \uace1\uc120\uc744 \ubcfc \uc218 \uc788\uc2b5\ub2c8\ub2e4. \ub0b4\ub824\ubcf4\uba74\uc11c \uc0b4\ud3b4\ubcf4\uc2ed\uc2dc\uc624; \uc77c\ubd80 \ubd84\ub958\ub294 \uac70\uc758 100%\uc758 \u201c\uc601\uc5ed\uc774 \uace1\uc120 \uc544\ub798\u201d\uc5d0 \uc788\uace0, \ub2e4\ub978 \ubd84\ub958\ub4e4\uc740 \uc774 \uc601\uc5ed\uc774 \ub354 \uc801\uc2b5\ub2c8\ub2e4: \uc5ec\uae30\uae4c\uc9c0 TensorBoard\uc640 PyTorch\uc758 \ud1b5\ud569\uc5d0 \ub300\ud574 \uc18c\uac1c\ud588\uc2b5\ub2c8\ub2e4. \ubb3c\ub860 TensorBoard\uc5d0\uc11c \uc81c\uacf5\ud558\ub294 \ubaa8\ub4e0 \uac83\ub4e4\uc744 Jupyter Notebook\uc5d0\uc11c\ub3c4 \ud560 \uc218 \uc788\uc9c0\ub9cc, TensorBoard\ub97c \uc0ac\uc6a9\ud558\uba74 \ub300\ud654\ud615 \uc2dc\uac01\ud654\uac00 \uae30\ubcf8\uc73c\ub85c \uc81c\uacf5\ub429\ub2c8\ub2e4.",
       "author": {
         "@type": "Organization",
         "name": "PyTorch Contributors",
         "url": "https://pytorch.org"
       },
       "image": "../_static/img/pytorch_seo.png",
       "mainEntityOfPage": {
         "@type": "WebPage",
         "@id": "/intermediate/tensorboard_tutorial.html"
       },
       "datePublished": "2023-01-01T00:00:00Z",
       "dateModified": "2023-01-01T00:00:00Z"
     }
 

article:modified_time2022-11-30T07:09:41+00:00
og:typearticle
og:site_namePyTorch Tutorials KR
og:image../_static/img/pytorch_seo.png
og:image:altPyTorch Tutorials KR
og:ignore_canonicaltrue
docsearch:languageko
docbuild:last-update2022년 11월 30일
None2
pytorch_projecttutorials

Links:

https://pytorch.kr/
PyTorch 시작하기 https://pytorch.kr/get-started/locally/
기본 익히기 https://tutorials.pytorch.kr/beginner/basics/intro.html
한국어 튜토리얼 https://tutorials.pytorch.kr/
한국어 모델 허브 https://pytorch.kr/hub/
Official Tutorials https://docs.pytorch.org/tutorials/
블로그 https://pytorch.kr/blog/
PyTorch API https://docs.pytorch.org/docs/
Domain API 소개 https://pytorch.kr/domains/
한국어 튜토리얼 https://tutorials.pytorch.kr/
Official Tutorials https://docs.pytorch.org/tutorials/
한국어 커뮤니티 https://discuss.pytorch.kr/
개발자 정보 https://pytorch.kr/resources/
Landscape https://landscape.pytorch.org/
https://tutorials.pytorch.kr/intermediate/tensorboard_tutorial.html
https://tutorials.pytorch.kr/intermediate/tensorboard_tutorial.html
PyTorch 시작하기https://pytorch.kr/get-started/locally/
기본 익히기https://tutorials.pytorch.kr/beginner/basics/intro.html
한국어 튜토리얼https://tutorials.pytorch.kr/
한국어 모델 허브https://pytorch.kr/hub/
Official Tutorialshttps://docs.pytorch.org/tutorials/
블로그https://pytorch.kr/blog/
PyTorch APIhttps://docs.pytorch.org/docs/
Domain API 소개https://pytorch.kr/domains/
한국어 튜토리얼https://tutorials.pytorch.kr/
Official Tutorialshttps://docs.pytorch.org/tutorials/
한국어 커뮤니티https://discuss.pytorch.kr/
개발자 정보https://pytorch.kr/resources/
Landscapehttps://landscape.pytorch.org/
Skip to main contenthttps://tutorials.pytorch.kr/intermediate/tensorboard_tutorial.html#main-content
v2.8.0+cu128https://tutorials.pytorch.kr/index.html
Intro https://tutorials.pytorch.kr/intro.html
Compilers https://tutorials.pytorch.kr/compilers_index.html
Domains https://tutorials.pytorch.kr/domains.html
Distributed https://tutorials.pytorch.kr/distributed.html
Deep Dive https://tutorials.pytorch.kr/deep-dive.html
Extension https://tutorials.pytorch.kr/extension.html
Ecosystem https://tutorials.pytorch.kr/ecosystem.html
Recipes https://tutorials.pytorch.kr/recipes_index.html
한국어 튜토리얼 GitHub 저장소https://github.com/PyTorchKorea/tutorials-kr
파이토치 한국어 커뮤니티https://discuss.pytorch.kr/
Intro https://tutorials.pytorch.kr/intro.html
Compilers https://tutorials.pytorch.kr/compilers_index.html
Domains https://tutorials.pytorch.kr/domains.html
Distributed https://tutorials.pytorch.kr/distributed.html
Deep Dive https://tutorials.pytorch.kr/deep-dive.html
Extension https://tutorials.pytorch.kr/extension.html
Ecosystem https://tutorials.pytorch.kr/ecosystem.html
Recipes https://tutorials.pytorch.kr/recipes_index.html
한국어 튜토리얼 GitHub 저장소https://github.com/PyTorchKorea/tutorials-kr
파이토치 한국어 커뮤니티https://discuss.pytorch.kr/
파이토치(PyTorch) 기본 익히기https://tutorials.pytorch.kr/beginner/basics/intro.html
PyTorch 소개 - YouTube 시리즈https://tutorials.pytorch.kr/beginner/introyt/introyt_index.html
PyTorch 소개https://tutorials.pytorch.kr/beginner/introyt/introyt1_tutorial.html
Pytorch Tensor 소개https://tutorials.pytorch.kr/beginner/introyt/tensors_deeper_tutorial.html
The Fundamentals of Autogradhttps://tutorials.pytorch.kr/beginner/introyt/autogradyt_tutorial.html
Building Models with PyTorchhttps://tutorials.pytorch.kr/beginner/introyt/modelsyt_tutorial.html
PyTorch TensorBoard 지원https://tutorials.pytorch.kr/beginner/introyt/tensorboardyt_tutorial.html
Training with PyTorchhttps://tutorials.pytorch.kr/beginner/introyt/trainingyt.html
Model Understanding with Captumhttps://tutorials.pytorch.kr/beginner/introyt/captumyt.html
PyTorch로 딥러닝하기: 60분만에 끝장내기https://tutorials.pytorch.kr/beginner/deep_learning_60min_blitz.html
텐서(Tensor)https://tutorials.pytorch.kr/beginner/blitz/tensor_tutorial.html
torch.autograd 에 대한 간단한 소개https://tutorials.pytorch.kr/beginner/blitz/autograd_tutorial.html
신경망(Neural Networks)https://tutorials.pytorch.kr/beginner/blitz/neural_networks_tutorial.html
분류기(Classifier) 학습하기https://tutorials.pytorch.kr/beginner/blitz/cifar10_tutorial.html
예제로 배우는 파이토치(PyTorch)https://tutorials.pytorch.kr/beginner/pytorch_with_examples.html
준비 운동: NumPyhttps://tutorials.pytorch.kr/beginner/examples_tensor/polynomial_numpy.html
파이토치(PyTorch): 텐서(Tensor)https://tutorials.pytorch.kr/beginner/examples_tensor/polynomial_tensor.html
PyTorch: 텐서(Tensor)와 autogradhttps://tutorials.pytorch.kr/beginner/examples_autograd/polynomial_autograd.html
PyTorch: 새 autograd Function 정의하기https://tutorials.pytorch.kr/beginner/examples_autograd/polynomial_custom_function.html
PyTorch: nnhttps://tutorials.pytorch.kr/beginner/examples_nn/polynomial_nn.html
PyTorch: optimhttps://tutorials.pytorch.kr/beginner/examples_nn/polynomial_optim.html
PyTorch: 사용자 정의 nn.Modulehttps://tutorials.pytorch.kr/beginner/examples_nn/polynomial_module.html
PyTorch: 제어 흐름(Control Flow) + 가중치 공유(Weight Sharing)https://tutorials.pytorch.kr/beginner/examples_nn/dynamic_net.html
torch.nn 이 실제로 무엇인가요?https://tutorials.pytorch.kr/beginner/nn_tutorial.html
Understanding requires_grad, retain_grad, Leaf, and Non-leaf Tensorshttps://tutorials.pytorch.kr/beginner/understanding_leaf_vs_nonleaf_tutorial.html
NLP from Scratchhttps://tutorials.pytorch.kr/intermediate/nlp_from_scratch_index.html
TensorBoard로 모델, 데이터, 학습 시각화하기https://tutorials.pytorch.kr/intermediate/tensorboard_tutorial.html
A guide on good usage of non_blocking and pin_memory() in PyTorchhttps://tutorials.pytorch.kr/intermediate/pinmem_nonblock.html
Visualizing Gradientshttps://tutorials.pytorch.kr/intermediate/visualizing_gradients_tutorial.html
https://tutorials.pytorch.kr/index.html
Introhttps://tutorials.pytorch.kr/intro.html
#https://tutorials.pytorch.kr/intermediate/tensorboard_tutorial.html#tensorboard
PyTorch로 딥러닝하기: 60분만에 끝장내기https://tutorials.pytorch.kr/beginner/deep_learning_60min_blitz.html
Fashion-MNIST datasethttps://github.com/zalandoresearch/fashion-mnist
분류기(Classifier) 학습하기https://tutorials.pytorch.kr/beginner/blitz/cifar10_tutorial.html
#https://tutorials.pytorch.kr/intermediate/tensorboard_tutorial.html#id1
#https://tutorials.pytorch.kr/intermediate/tensorboard_tutorial.html#id2
make_gridhttps://pytorch.org/vision/stable/utils.html#torchvision.utils.make_grid
http://localhost:6006http://localhost:6006
#https://tutorials.pytorch.kr/intermediate/tensorboard_tutorial.html#tensorboard-inspect
#https://tutorials.pytorch.kr/intermediate/tensorboard_tutorial.html#tensorboard-projector
add_embeddinghttps://pytorch.org/docs/stable/tensorboard.html#torch.utils.tensorboard.writer.SummaryWriter.add_embedding
#https://tutorials.pytorch.kr/intermediate/tensorboard_tutorial.html#id3
add_scalarhttps://pytorch.org/docs/stable/tensorboard.html#torch.utils.tensorboard.writer.SummaryWriter.add_scalar
여기https://www.scikit-yb.org/en/latest/api/classifier/prcurve.html
#https://tutorials.pytorch.kr/intermediate/tensorboard_tutorial.html#id4
이전 NLP from Scratch https://tutorials.pytorch.kr/intermediate/nlp_from_scratch_index.html
다음 A guide on good usage of non_blocking and pin_memory() in PyTorch https://tutorials.pytorch.kr/intermediate/pinmem_nonblock.html
PyData Sphinx Themehttps://pydata-sphinx-theme.readthedocs.io/en/stable/index.html
이전 NLP from Scratch https://tutorials.pytorch.kr/intermediate/nlp_from_scratch_index.html
다음 A guide on good usage of non_blocking and pin_memory() in PyTorch https://tutorials.pytorch.kr/intermediate/pinmem_nonblock.html
1. TensorBoard 설정https://tutorials.pytorch.kr/intermediate/tensorboard_tutorial.html#id1
2. TensorBoard에 기록하기https://tutorials.pytorch.kr/intermediate/tensorboard_tutorial.html#id2
3. TensorBoard를 사용하여 모델 살펴보기(inspect)https://tutorials.pytorch.kr/intermediate/tensorboard_tutorial.html#tensorboard-inspect
4. TensorBoard에 “Projector” 추가하기https://tutorials.pytorch.kr/intermediate/tensorboard_tutorial.html#tensorboard-projector
5. TensorBoard로 모델 학습 추적하기https://tutorials.pytorch.kr/intermediate/tensorboard_tutorial.html#id3
6. TensorBoard로 학습된 모델 평가하기https://tutorials.pytorch.kr/intermediate/tensorboard_tutorial.html#id4
torchaohttps://docs.pytorch.org/ao
torchrechttps://docs.pytorch.org/torchrec
torchfthttps://docs.pytorch.org/torchft
TorchCodechttps://docs.pytorch.org/torchcodec
torchvisionhttps://docs.pytorch.org/vision
ExecuTorchhttps://docs.pytorch.org/executorch
PyTorch on XLA Deviceshttps://docs.pytorch.org/xla
GitHub로 이동https://github.com/PyTorchKorea
튜토리얼로 이동https://tutorials.pytorch.kr/
커뮤니티로 이동https://discuss.pytorch.kr/
https://pytorch.kr/
파이토치 한국 사용자 모임https://pytorch.kr/
사용자 모임 소개https://pytorch.kr/about
기여해주신 분들https://pytorch.kr/contributors
리소스https://pytorch.kr/resources/
행동 강령https://pytorch.kr/coc
행동 강령https://pytorch.kr/coc
Linux Foundation의 정책https://www.linuxfoundation.org/policies/
our code of conducthttps://pytorch.kr/coc
Linux Foundation's policieshttps://www.linuxfoundation.org/policies/
Cookies Policyhttps://www.facebook.com/policies/cookies/
Sphinxhttps://www.sphinx-doc.org/
PyData Sphinx Themehttps://pydata-sphinx-theme.readthedocs.io/en/stable/index.html

Viewport: width=device-width, initial-scale=1


URLs of crawlers that visited me.