<jupyter_start><jupyter_text>-->--><jupyter_code>import torch
from scipy.misc import face
img = face().astype('float')
img = torch.tensor(img)
batch = img.permute(2, 0, 1)
batch = batch.unsqueeze(0)
# batch.shape
loader = [(batch, '')]
nimages = 0
mean = 0.
std = 0.

for batch, _ in loader:

    print(batch.shape)
    
    batch = batch.view(data.size(0), batch.size(1), -1)

    print(batch.shape)
    
    # update total number of images
    nimages += batch.size(0)
    # compute mean and std here
    mean += batch.mean(2).sum(0)
    std += batch.std(2).sum(0)
    
    print(nimages)
    print(mean)
    print(std)
    
mean /= nimages
std /= nimages

print(mean)
print(std)
import torch
from torch.utils.data import TensorDataset, DataLoader

data = torch.randn(64, 3, 28, 28)
labels = torch.zeros(64, 1)
dataset = TensorDataset(data, labels)
loader = DataLoader(dataset, batch_size=8)

nimages = 0
mean = 0.
std = 0.
for batch, _ in loader:
    # Rearrange batch to be the shape of [B, C, W * H]
    batch = batch.view(batch.size(0), batch.size(1), -1)
    # Update total number of images
    nimages += batch.size(0)
    # Compute mean and std here
    mean += batch.mean(2).sum(0) 
    std += batch.std(2).sum(0)

# Final step
mean /= nimages
std /= nimages

print(mean)
print(std)<jupyter_output>tensor([ 0.0091, -0.0010,  0.0024])
tensor([1.0035, 0.9965, 0.9973])
{'fraction_non_alphanumeric': 0.15334302325581395, 'fraction_numerical': 0.04869186046511628, 'mean_word_length': 3.236923076923077, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '483529', 'license': 'CC0-1.0', 'n_tokens_mistral': 564, 'n_tokens_neox': 524, 'n_words': 136, 'path': 'channels-mean-std.ipynb', 'repo_name': 'trsvchn/stackoverflow-notebooks', 'size': '1376'}