-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnn_linear.py
38 lines (26 loc) · 937 Bytes
/
nn_linear.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
import torch
import torchvision
from torch import nn
from torch.nn import Conv2d, Linear
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter
dataset=torchvision.datasets.CIFAR10("../daTa",train=False,transform=torchvision.transforms.ToTensor(),download=True)
dataloader=DataLoader(dataset,batch_size=64)
class Qianshi(nn.Module):
def __init__(self):
super(Qianshi, self).__init__()
self.linear=Linear(196608,10)
# in_feature=196608 out_feature=10
def forward(self,input):
output=self.linear(input)
return output
qianshi=Qianshi()
for data in dataloader:
imgs,targets=data
print(imgs.shape)
# output=torch.reshape(imgs,(1,1,1,-1))
output=torch.flatten(imgs)
# 用flatten不用reshape 直接对feature动手
print(output.shape)
output=qianshi(output)
print(output.shape)