UOMOP

Custom Dataset(Gaussian Filtered Cifar 10) 본문

Wireless Comm./CISL

Custom Dataset(Gaussian Filtered Cifar 10)

Happy PinGu 2023. 8. 4. 15:43
import cv2
import math
import time
import torch
import random
import torchvision
import numpy as np
from PIL import Image
import torch.nn as nn
from numpy import sqrt
import torch.optim as optim
import torch.nn.functional as f
import matplotlib.pyplot as plt
import torchvision.transforms as tr
from torchvision import datasets
from torch.utils.data import DataLoader, Dataset

import os
os.environ['KMP_DUPLICATE_LIB_OK']='True'

def gaussian_filter(img, kernel_size) :

    return cv2.GaussianBlur(img, (kernel_size, kernel_size), 0)

transf = tr.Compose([tr.ToTensor()])

dataset = torchvision.datasets.CIFAR10(root = './data', train = True, download = True, transform = transf)

dataloader = DataLoader(dataset, batch_size = 64, shuffle = False)

image_saver = []

#print(len(dataloader))
u = 0
filsize = 23

for data in dataloader:

    u += 1

    for i in range(len(data[0])) :
        #print(len(data[0]))

        input = data[0]
        #print(input.size())

        filtered_img = gaussian_filter(input[i].permute(1, 2, 0).numpy(), filsize) * 255.0   # 3, 5, 7, 9, 11, 13, 15, 17, 19
        b, g, r = cv2.split(filtered_img)  # img파일을 b,g,r로 분리
        img = cv2.merge([r, g, b])  # b, r을 바꿔서 Merge
        #plt.imshow(img)
        #plt.show()

        #image_saver.append(filtered_img)

        cv2.imwrite('custom_data/gaussian/filsize_' + str(filsize) +'/' + str(64 * (u-1) + i) + '.jpg', img)

'Wireless Comm. > CISL' 카테고리의 다른 글

이거 성능 왜 높게 나옴?  (0) 2023.08.07
AWGN_cifar10_20230804  (0) 2023.08.04
DeepJSCC  (0) 2023.08.02
AWGN(pi=1024 si=0)  (0) 2023.07.28
AWGN(pi=64, si=0)  (0) 2023.07.27
Comments