This repository was archived by the owner on Aug 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtorc.py
51 lines (40 loc) · 1.55 KB
/
torc.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
43
44
45
46
47
48
49
50
51
import torch, torchvision
from visdom import Visdom
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torch.autograd import Variable
import matplotlib.pyplot as plt
import cv2
import numpy as np
T = torchvision.transforms.Compose([torchvision.transforms.ToTensor(),
torchvision.transforms.Normalize((0.1307,),(0.3081,))])
data_train = torchvision.datasets.MNIST('/files/', train=True, download=False,transform=T)
data_test = torchvision.datasets.MNIST('/files/', train=False, download=False,transform=T)
train_loader = torch.utils.data.DataLoader(data_train, batch_size=64, shuffle=True)
test_loader = torch.utils.data.DataLoader(data_test, batch_size=1000, shuffle=True)
examples = enumerate(train_loader)
batch_idx, (example_data, example_targets) = next(examples)
print(example_data.shape) #128 images = # batch, single color channel (greyscale) and 28x28 "pixels"
# print(example_targets.shape) #128 targets
# **** Graph Y images ****
Y = 6
fig = plt.figure()
for i in range(Y):
plt.subplot(2,3,i+1)
plt.tight_layout()
plt.imshow(example_data[i][0], cmap='gray', interpolation='none')
plt.title("Target: {}".format(example_targets[i]))
plt.xticks([])
plt.yticks([])
# plt.show()
# img = example_data[1][0]
# sobel_y = np.array([[-1,-2,-1],[0,0,0],[1,2,1]])
# new = cv2.filter2D(img, -1, sobel_y)
# plt.imshow(new, cmap='gray')
# plt.show()
# **** Neural Net ****
# class Net(nn.Module):
# def __init__(self):
# super(Net,self).__init__()
# self.conv1 = nn