MCPcopy Index your code
hub / github.com/Newmu/dcgan_code / batchnorm

Function batchnorm

lib/ops.py:52–83  ·  view source on GitHub ↗

batchnorm with support for not using scale and shift parameters as well as inference values (u and s) and partial batchnorm (via a) will detect and use convolutional or fully connected version

(X, g=None, b=None, u=None, s=None, a=1., e=1e-8)

Source from the content-addressed store, hash-verified

50 return T.concatenate([x, y*T.ones((x.shape[0], y.shape[1], x.shape[2], x.shape[3]))], axis=1)
51
52def batchnorm(X, g=None, b=None, u=None, s=None, a=1., e=1e-8):
53 """
54 batchnorm with support for not using scale and shift parameters
55 as well as inference values (u and s) and partial batchnorm (via a)
56 will detect and use convolutional or fully connected version
57 """
58 if X.ndim == 4:
59 if u is not None and s is not None:
60 b_u = u.dimshuffle('x', 0, 'x', 'x')
61 b_s = s.dimshuffle('x', 0, 'x', 'x')
62 else:
63 b_u = T.mean(X, axis=[0, 2, 3]).dimshuffle('x', 0, 'x', 'x')
64 b_s = T.mean(T.sqr(X - b_u), axis=[0, 2, 3]).dimshuffle('x', 0, 'x', 'x')
65 if a != 1:
66 b_u = (1. - a)*0. + a*b_u
67 b_s = (1. - a)*1. + a*b_s
68 X = (X - b_u) / T.sqrt(b_s + e)
69 if g is not None and b is not None:
70 X = X*g.dimshuffle('x', 0, 'x', 'x') + b.dimshuffle('x', 0, 'x', 'x')
71 elif X.ndim == 2:
72 if u is None and s is None:
73 u = T.mean(X, axis=0)
74 s = T.mean(T.sqr(X - u), axis=0)
75 if a != 1:
76 u = (1. - a)*0. + a*u
77 s = (1. - a)*1. + a*s
78 X = (X - u) / T.sqrt(s + e)
79 if g is not None and b is not None:
80 X = X*g + b
81 else:
82 raise NotImplementedError
83 return X
84
85def deconv(X, w, subsample=(1, 1), border_mode=(0, 0), conv_mode='conv'):
86 """

Callers 8

genFunction · 0.90
discrimFunction · 0.90
genFunction · 0.90
discrimFunction · 0.90
bnorm_statisticsFunction · 0.90
modelFunction · 0.90
genFunction · 0.90
discrimFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected