-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.py
38 lines (32 loc) · 1011 Bytes
/
tools.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 numpy as np
from torch.nn import init
import matplotlib.pyplot as plt
def gaussian_intiailize(model, std=.01):
modules = [
m for n, m in model.named_modules() if
'conv' in n or 'fc' in n
]
parameters = [
p for
m in modules for
p in m.parameters()
]
for p in parameters:
if p.dim() >= 2:
init.normal(p, std=std)
else:
init.constant(p, 0)
def make_plots(imgs, path=None):
imgs = imgs
fig = plt.figure()
for idx in range(16):
ax = fig.add_subplot(4, 4, idx+1) # this line adds sub-axes
ax.xaxis.set_visible(False) # same for y axis.
ax.yaxis.set_visible(False) # same for y axis.
ax.set_aspect('auto')
img = imgs[idx]
img = img.transpose(2, 1, 0)
img = np.rot90(np.rot90(np.rot90(img)))
ax.imshow(img) # this line creates the image using the pre-defined sub axes
plt.savefig(path+".png", transparent=True)
plt.show()