본문 바로가기

Upstage AI Lab 2기

Upstage AI Lab 2기 [Day061]

Upstage AI Lab 2기

2024년 3월 11일 (월) Day_061

 

오늘의 todo

  • [ ] cnn module 에 parameter counter 넣기
  • [ ] cnn module logging 넣기?
  • [ ] dataset class 에 transform 넣기
  • [ ] 지금까지의 작업 정리하고 순차적으로 실행해서 wandb 기록
  • [ ] vgg 구현 (논문 앞부분 읽던 중)

 

참고 자료 (given from 승현님) - normalize에 넣는 평균, 표준편차 값에 대한 설명

https://dacon.io/codeshare/4750

 

VGG 논문의 configuration 부분에서 3*3 커널만 사용한다, stride=1, padding=1이라는 부분 외에

데이터에 대한 수정 작업은 mean값을 뺀 것 외에는 없다는 내용을 읽음.

 

base_path = './src/datasets/cifar-10-python/cifar-10-batches-py/'

cifar10_train_dataset = CustomCIFAR10Dataset(root_dir = base_path, is_train = True)

train_dataloader = DataLoader(cifar10_train_dataset, shuffle = True)

mean_accumulator = torch.zeros(3)
std_accumulator = torch.zeros(3)

for img, _ in train_dataloader:
    mean_accumulator += img.mean(dim=(0, 2, 3))
    std_accumulator += img.std(dim=(0, 2, 3))
    
means = mean_accumulator/len(train_dataloader.dataset)
stds = std_accumulator/len(train_dataloader.dataset)

print("Means : ", means, "Stds : ", stds)
# Means :  tensor([0.4914, 0.4822, 0.4465])
# Stds :  tensor([0.2023, 0.1994, 0.2010])

 

 

Normalize를 적용하기 위해 작업을 수정하는 과정에서

강의 코드 중

mnist_transform = T.Compose([
    T.ToTensor(), 
])

train_dataset = torchvision.datasets.MNIST(download_root, transform=mnist_transform, train=True, download=True)

에서 transform=mnist_transform이 어느 단에서 작동하는지 궁금해짐

 

torchvision

-> datasets

-> from .mnist import EMNIST, FashionMNIST, KMNIST, MNIST, QMNIST

 

 

MNIST

mnist.py

 

from .vision import VisionDataset

 

 

 

 

 

Exception has occurred: RuntimeError
shape '[3, 32, 32]' is invalid for input of size 30720000
  File "G:\내 드라이브\009_AI공부\09_Upstage Lab AI 2기\##_upstage lab\2주차\code\src\datasets\cifar10_dataset_trial2.py", line 30, in __init__
    data = torch.Tensor(data).reshape(3, 32, 32) / 255.0
  File "G:\내 드라이브\009_AI공부\09_Upstage Lab AI 2기\##_upstage lab\2주차\code\main.py", line 38, in <module>
    cifar10_train_dataset = CustomCIFAR10Dataset(root_dir = base_path, is_train = True)
RuntimeError: shape '[3, 32, 32]' is invalid for input of size 30720000

 

 

from torch.utils.data import Dataset

 

# print(len(cifar10_train_dataset))
# # 50000
# print(type(cifar10_train_dataset))
# # <class 'src.datasets.cifar10_dataset.CustomCIFAR10Dataset'>
# print(len(cifar10_train_dataset.data))
# # 50000
# print(len(cifar10_train_dataset.targets))
# # 50000
# print(cifar10_train_dataset.data[0])
# # tensor([[[0.6980, 0.6980, 0.6980,  ..., 0.6667, 0.6588, 0.6471],
# #          [0.7059, 0.7020, 0.7059,  ..., 0.6784, 0.6706, 0.6588],
# #          [0.6941, 0.6941, 0.6980,  ..., 0.6706, 0.6627, 0.6549],
# #          ...,
# #          [0.4392, 0.4431, 0.4471,  ..., 0.3922, 0.3843, 0.3961],
# #          [0.4392, 0.4392, 0.4431,  ..., 0.4000, 0.4000, 0.4000],
# #          [0.4039, 0.3922, 0.4039,  ..., 0.3608, 0.3647, 0.3569]],

# #         [[0.6902, 0.6902, 0.6902,  ..., 0.6588, 0.6510, 0.6392],
# #          [0.6980, 0.6941, 0.6980,  ..., 0.6706, 0.6627, 0.6510],
# #          [0.6863, 0.6863, 0.6902,  ..., 0.6627, 0.6549, 0.6471],
# #          ...,
# #          [0.4196, 0.4275, 0.4314,  ..., 0.3804, 0.3686, 0.3725],
# #          [0.4000, 0.4039, 0.4039,  ..., 0.3725, 0.3647, 0.3608],
# #          [0.3765, 0.3647, 0.3725,  ..., 0.3294, 0.3373, 0.3294]],

# #         [[0.7412, 0.7412, 0.7412,  ..., 0.7059, 0.6941, 0.6824],
# #          [0.7490, 0.7451, 0.7490,  ..., 0.7137, 0.7059, 0.6941],
# #          [0.7373, 0.7373, 0.7412,  ..., 0.7059, 0.6980, 0.6902],
# #          ...,
# #          [0.4196, 0.4235, 0.4314,  ..., 0.3686, 0.3647, 0.3725],
# #          [0.3961, 0.4000, 0.4039,  ..., 0.3647, 0.3569, 0.3569],
# #          [0.3608, 0.3529, 0.3686,  ..., 0.3137, 0.3137, 0.3020]]])
# # print(len(cifar10_test_dataset))
# # 10000

 

 

 

매일 마주하는... 에러들...........ㅜ

 


#01.

 

 

Epoch [32 / 100], Train Loss : 1.7070, Train Acc : 0.7610
Epoch [32 / 100], Valid Loss : 1.8274, Valid Acc : 0.6304
Early stopping at epoch 32
Valid max accuracy :  0.6439

Custom CNN test accuracy :  0.6478

 

 

 


#02.

 

Epoch [32 / 100], Train Loss : 1.7070, Train Acc : 0.7610

Epoch [32 / 100], Valid Loss : 1.8274, Valid Acc : 0.6304

Early stopping at epoch 32

Valid max accuracy : 0.6439

Custom CNN test accuracy : 0.6478

 

 

 


#3

 

 

Epoch [39 / 100], Train Loss : 1.7316, Train Acc : 0.7298
Epoch [39 / 100], Valid Loss : 1.8127, Valid Acc : 0.6478
Early stopping at epoch 39
Valid max accuracy :  0.6564

Custom CNN test accuracy :  0.6494

 

 

 

 

https://pytorch.org/vision/stable/transforms.html