-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculate_mean_std.py
41 lines (34 loc) · 958 Bytes
/
calculate_mean_std.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
39
40
41
import torchvision
import numpy as np
import os, time, torch
from tqdm import tqdm
from torchvision import transforms
from torch.utils.data import DataLoader
from torch.utils.data.dataset import Dataset
from datasets.GANZIN_dataset import *
data_path = "./ganzin_dataset_final/train"
transform_img = transforms.Compose([
transforms.ToTensor(),
])
image_data = torchvision.datasets.ImageFolder(
root=data_path, transform=transform_img
)
image_data_loader = DataLoader(
image_data,
batch_size=len(image_data),
shuffle=False,
num_workers=8
)
image_data_loader = DataLoader(
image_data,
# batch size is whole datset
batch_size=len(image_data),
shuffle=False,
num_workers=8)
def mean_std(loader):
images, labels = next(iter(loader))
# shape of images = [b,c,w,h]
mean, std = images.mean([0,2,3]), images.std([0,2,3])
return mean, std
mean, std = mean_std(image_data_loader)
print("mean and std: \n", mean, std)