In [35]:
import torch
import torchvision.datasets as datasets
import torch.utils.data as data
import torchvision.models as models
import torchvision.transforms as transforms
from torch.autograd import Variable
import os

import matplotlib.pyplot as plt
%matplotlib inline

import numpy as np

In [ ]:
class TinyImageDataset(Dataset):

In [ ]:


In [75]:
print("Loading stored model ...")
model = models.resnet18(pretrained=True)
print("Loaded model successfully.")

# load data set
print("Reading data...")
val_dir = os.path.expanduser('~/nta/datasets/tiny-imagenet-200/val')
val_dataset = datasets.ImageFolder(val_dir, transform=transforms.ToTensor())
val_loader = data.DataLoader(val_dataset, batch_size=128)
print("Loaded: %s" % val_dir)


Loading stored model ...
Loaded model successfully.
Reading data...
Loaded: /Users/lsouza/nta/datasets/tiny-imagenet-200/val
correct = 0 total = 0 for batch in val_loader: images, labels = batch outputs = model(Variable(images)) _, predicted = torch.max(outputs.data, 1) total += labels.size(0) print(labels.float().mean().item()) correct += (predicted == labels).sum().item() print('Progress --- total: %s, correct: %s' % (total, correct)) print('Accuracy of the network on the 10000 test images: %s %%', (100 * correct / total))

In [21]:
predicted


Out[21]:
tensor([929, 107, 646, 917,   7, 990, 354, 981, 702, 530, 321, 508, 573, 584,
        567, 611])

In [22]:
labels


Out[22]:
tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

In [25]:
val_loader


Out[25]:
<torch.utils.data.dataloader.DataLoader at 0x12d4499b0>

In [78]:
input, target = next(iter(val_loader))
input.shape


Out[78]:
torch.Size([128, 3, 64, 64])

In [84]:
rand = np.random.randint(input.shape[0])
plt.imshow(input[rand].permute(1,2,0).numpy()), target[rand]


Out[84]:
(<matplotlib.image.AxesImage at 0x1340194a8>, tensor(0))

In [86]:
target


Out[86]:
tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0])

In [ ]: