-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
68 lines (45 loc) · 1.46 KB
/
test.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
###
# test drive models with dummy inputs
import torch
import torch.nn as nn
### local imports
from models import LeNet5, LeNet5Seq, LeNet5v2, LeNet5v2b, LeNet5_28x28
model = LeNet5()
#####
### single input (channels,height,width) => (1,32,32)
input = torch.randn(1,32,32)
print(f"{input.shape} {input.ndim}d", input)
output = model(input)
print(f"{output.shape} {output.ndim}d", output)
###
### try batch of size one => (1,1,32,32)
print("---")
input = input.unsqueeze(0)
print(f"{input.shape} {input.ndim}d", input)
output = model(input)
print(f"{output.shape} {output.ndim}d", output)
###
### try batch of size of two => (2,1,32,32)
print("---")
input = torch.stack( (torch.randn(1,32,32),torch.randn(1,32,32)) )
print(f"{input.shape} {input.ndim}d", input)
output = model(input)
print(f"{output.shape} {output.ndim}d", output)
####
# try 28x28 version
#
# - batch input (batch,channels,height,width) => (1,1,28,28)
model = LeNet5_28x28()
input = torch.randn(1,28,28).unsqueeze(0)
print(f"{input.shape} {input.ndim}d", input)
output = model(input)
print(f"{output.shape} {output.ndim}d", output)
###########################
# try alt seq version for 32x32
# (only works with batch input NOT single input)
model = LeNet5Seq()
input = torch.randn(1,32,32).unsqueeze(0)
print(f"{input.shape} {input.ndim}d", input)
output = model(input)
print(f"{output.shape} {output.ndim}d", output)
print( "bye")