-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.py
47 lines (35 loc) · 817 Bytes
/
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
import torch
import models
import numpy as np
m = models.NoisyReLU(a=.9, b=1.1, inplace=True)
for i in range(3):
if 2==i:
x = np.random.rand(2,2).astype('f') - 0.5
else:
x = np.random.rand(3,2).astype('f') - 0.5
x = torch.from_numpy(x)
z = x.cuda()
z = torch.autograd.Variable(z, requires_grad=True)
m.cuda()
print('input: ', z)
res = m(z)
print('output: ', res)
o = res.sum()
o.backward()
print('input.grad: ', z.grad)
print('-------------------')
print('=========== eval ============')
m.eval()
for i in range(2):
if 1==i:
x = np.random.rand(5,2).astype('f') - 0.5
else:
x = np.random.rand(1,2).astype('f') - 0.5
x = torch.from_numpy(x)
z = x.cuda()
z = torch.autograd.Variable(z)
m.cuda()
print('input: ', z)
res = m(z)
print('output: ', res)
print('-------------------')