거의 알고리즘 일기장

visdom 사용법 본문

pytorch 사용법

visdom 사용법

건우권 2020. 9. 22. 16:05
Untitled3
In [1]:
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.data import DataLoader
import torchvision.datasets as datasets
from torch.autograd import Variable
import visdom
import torch.optim as optim
In [3]:
vis = visdom.Visdom()
textwindow = vis.text("Hello Pytorch")
Setting up a new session...
In [9]:
import torchvision
import torchvision.transforms as transforms
#이미지 불러오기
transform = transforms.Compose([transforms.ToTensor(),
                               transforms.Normalize((0.5,),(0.5,))])

trainset = torchvision.datasets.MNIST(root = './data',
                                     train = True,
                                     download = True,
                                     transform = transform)

testset = torchvision.datasets.MNIST(root = './data',
                                     train = False,
                                     download = True,
                                     transform = transform)

trainloader = DataLoader(trainset, batch_size = 8, shuffle = True, num_workers = 2)
testloader = DataLoader(testset, batch_size = 8, shuffle = False, num_workers = 2)
In [11]:
for i, data in enumerate(trainloader):
    img, label = data
    vis.image(img[0])
    vis.images(img)
    break
In [12]:
plt = vis.line(Y= torch.randn(5))
In [15]:
import numpy as np
plot = vis.line(Y= torch.randn(5), X = np.array([0,1,2,3,4]))
In [16]:
#업데이트
vis.line(Y=torch.randn(1), X=np.array([5]), win=plot, update = 'append')
Out[16]:
'window_38dece7762091e'
In [17]:
for i in range(500):
    vis.line(Y=torch.randn(1), X=np.array([i+5]), win=plot, update = 'append')
In [ ]:
# plot에 두개 그리기
vis.line(Y=torch.randn(10, 2), X=np.column_stack((np.arange(0,10), np.arange(0,10))))
In [ ]:
#plot의 형태 변형 및 정보 추가
vis.line(Y=torch.randn(10, 2), X =np.column_stack((np.arange(0, 10), np.arange(0, 10))),
        opts = dict(title='hello',
                   showlegend = True))
In [ ]:
 
반응형
Comments