MCPcopy Index your code
hub / github.com/pytorch/tutorials / denorm

Function denorm

beginner_source/fgsm_tutorial.py:227–244  ·  view source on GitHub ↗

Convert a batch of tensors to their original scale. Args: batch (torch.Tensor): Batch of normalized tensors. mean (torch.Tensor or list): Mean used for normalization. std (torch.Tensor or list): Standard deviation used for normalization. Returns: torch.

(batch, mean=[0.1307], std=[0.3081])

Source from the content-addressed store, hash-verified

225
226# restores the tensors to their original scale
227def denorm(batch, mean=[0.1307], std=[0.3081]):
228 """
229 Convert a batch of tensors to their original scale.
230
231 Args:
232 batch (torch.Tensor): Batch of normalized tensors.
233 mean (torch.Tensor or list): Mean used for normalization.
234 std (torch.Tensor or list): Standard deviation used for normalization.
235
236 Returns:
237 torch.Tensor: batch of tensors without normalization applied to them.
238 """
239 if isinstance(mean, list):
240 mean = torch.tensor(mean).to(device)
241 if isinstance(std, list):
242 std = torch.tensor(std).to(device)
243
244 return batch * std.view(1, -1, 1, 1) + mean.view(1, -1, 1, 1)
245
246
247######################################################################

Callers 1

testFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected