-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.py
37 lines (29 loc) · 1.09 KB
/
input.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
import glob
import numpy as np
import os
from PIL import Image
import torch
from torchvision import transforms, datasets
data_transform = transforms.Compose([
# transforms.RandomSizedCrop(224),
# transforms.RandomHorizontalFlip(),
transforms.ToTensor()
])
face_dataset = datasets.ImageFolder('train', transform=data_transform)
dataset_loader = torch.utils.data.DataLoader(face_dataset,
batch_size=4, shuffle=True,
num_workers=4)
for i, (input, target) in enumerate(dataset_loader):
input_var = torch.autograd.Variable(input)
target_var = torch.autograd.Variable(target)
# reference : https://github.com/pytorch/examples/blob/master/imagenet/main.py#L97-L121
"""
loader = transforms.Compose([
transforms.ToTensor()]) # transform it into a torch tensor
def image_loader(image_name):
image = Image.open(image_name)
image = Variable(loader(image))
# fake batch dimension required to fit network's input dimensions
image = image.unsqueeze(0)
return image
"""