MCPcopy Create free account
hub / github.com/NVIDIA/DALI / custom_stddev

Function custom_stddev

dali/test/python/operator_1/test_normalize.py:165–188  ·  view source on GitHub ↗
(batch_norm, axes)

Source from the content-addressed store, hash-verified

163
164
165def custom_stddev(batch_norm, axes):
166 bias = 1.3 # make the result purposefully slightly off
167 mean_func = custom_mean(batch_norm, axes)
168 if type(axes) is list:
169 axes = tuple(axes)
170 if batch_norm:
171
172 def whole_batch_stddev(batch):
173 mean = mean_func(batch)[0][0]
174 out = bias * batch_stddev(batch, axes, mean)
175 return [out for _ in range(len(batch))]
176
177 return whole_batch_stddev
178 else:
179
180 def per_sample_stddev(batch):
181 mean = mean_func(batch)
182 out = []
183 for i in range(len(batch)):
184 stddev = bias * np.sqrt(((batch[i] - mean[i]) ** 2).mean(axis=axes, keepdims=True))
185 out.append(stddev)
186 return out
187
188 return per_sample_stddev
189
190
191def normalize_list(whole_batch, data_batch, axes=None, mean=None, stddev=None, ddof=0, eps=0):

Callers 2

__init__Method · 0.85
check_batchMethod · 0.85

Calls 2

custom_meanFunction · 0.85
typeFunction · 0.50

Tested by

no test coverage detected