Notice
Recent Posts
Recent Comments
Link
거의 알고리즘 일기장
custom dataset사용방법 _ image의 경우 본문
In [14]:
import os
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
import torchvision
from torch.utils.data import DataLoader, Dataset
import PIL.Image as Image
import matplotlib.pyplot as plt
import torchvision.transforms as transforms
import numpy as np
In [15]:
#custom
trans = transforms.Compose([transforms.Resize((100, 100)),
transforms.ToTensor(),
transforms.Normalize((0.5,0.5,0.5),(0.5,0.5,0.5))])
trainset = torchvision.datasets.ImageFolder(root='./mydraw', transform=trans)
In [16]:
len(trainset)
Out[16]:
In [17]:
trainloader = DataLoader(trainset, batch_size= 36, shuffle = False, num_workers = 2)
In [18]:
dataiter = iter(trainloader)
images, labels = dataiter.next()
In [22]:
def imshow(img):
img = img/2 + 0.5
np_img = img.numpy()
plt.imshow(np.transpose(np_img, (1, 2, 0)))
print(np_img.shape)
print((np.transpose(np_img, (1,2,0))).shape)
classes = ('airplane', 'apple', 'book', 'bycicle', 'car', 'eye', 'glasses', 'smile', 'tree')
In [25]:
print(images.shape)
imshow(torchvision.utils.make_grid(images, nrow=4))
print(images.shape)
print((torchvision.utils.make_grid(images)).shape)
print(''.join('%s ' %classes[labels[j]] for j in range(36)))
In [ ]:
반응형
'pytorch 사용법' 카테고리의 다른 글
visdom 사용법 (0) | 2020.09.22 |
---|---|
network를 Sequential을 이용해서 간단하게 만들기 & 모델 저장,불러오기 (0) | 2020.09.22 |
optim & criterion (0) | 2020.09.21 |
make NN (0) | 2020.09.21 |
Data Loader 사용법 (0) | 2020.09.21 |
Comments