-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataset_transform.py
42 lines (35 loc) · 1.11 KB
/
dataset_transform.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import torchvision
from torchvision import transforms
from torch.utils.data import DataLoader
from torch.utils.data import Dataset
import torch
import numpy as np
import os
import cv2
from tensorboardX import SummaryWriter
dataset_transform = transforms.Compose([
transforms.ToTensor(),
# transforms.RandomResizedCrop(224),
transforms.RandomHorizontalFlip(),
transforms.Normalize(
mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225]
)
])
train_set = torchvision.datasets.CIFAR10(root='./dataset_C', train=True, transform=dataset_transform, download=True)
test_set = torchvision.datasets.CIFAR10(root='./dataset_C', train=False, transform=dataset_transform, download=True)
# print(test_set[0])
# print(test_set.classes)
# img, target = test_set[0]
# print(img)
# # target here is the index of the class
# print(target)
# print(test_set.classes[target])
# img.show()
print(test_set[0])
writer = SummaryWriter('p10')
for i in range(10):
# img is a tensor, test_set[i] can get the i-th data in the test_set
img, target = test_set[i]
writer.add_image('test_set', img, i)
writer.close()