728x90
반응형
import torch
from tqdm.notebook import tqdm
import glob
from PIL import Image
from torchvision.transforms import ToTensor
target_path = "./images/*"
img_lst = glob.glob(target_path)
totensor = ToTensor()
img_val_lst = []
for img in tqdm(img_lst):
img_RGB = Image.open(img).convert("RGB")
img_val = totensor(img_RGB)
img_val_lst.append(img_val)
mean = torch.zeros(3)
std = torch.zeros(3)
print('==> Computing mean and std..')
for inputs in tqdm(img_val_lst):
for i in range(3):#RGB
mean[i] += inputs[i,:,:].mean()
std[i] += inputs[i,:,:].std()
mean.div_(len(img_val_lst))
std.div_(len(img_val_lst))
print(mean, std)
728x90
반응형
'머신러닝 > Computer Vision' 카테고리의 다른 글
[matplotlib] plt warning (More than 20 figures have been opened.) (0) | 2023.04.03 |
---|---|
[matplotlib] hatches, pattern (0) | 2023.04.03 |
[PascalVOC] Generate Pascal VOC(polygon) xml 생성(Labelme Json to voc xml) (0) | 2023.03.13 |
[Labelme2COCO] (0) | 2023.02.23 |
[PIL] 이미지 위에 반투명 도형 그리기, 글자 쓰기 / Drawing transparent Polygon on image (2) | 2023.02.15 |