AutoEncoder fashion MNIST

fashion MNIST 데이터셋을 이용하여 기본적인 Autoencoder를 구현하는 페이지다.

import torch
import torchvision
import torch.nn.functional as F
from torch import nn, optim
from torchvision import transforms, datasets

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import numpy as np

Autoencoder 구현에 앞서 필요한 라이브러리를 import 해준다.

EPOCH = 10
BATCH_SIZE = 64
USE_CUDA = torch.cuda.is_available()
DEVICE = torch.device("cuda" if USE_CUDA else "cpu")
print("Using Device: ", DEVICE)
trainset =  datasets.FashionMNIST(
    root ='./.data/',
    train = True, download = True,
    transform = transforms.ToTensor()
)
train_loader = torch.utils.data.DataLoader(
    dataset = trainset,
    batch_size = BATCH_SIZE,
    shuffle = True,
    num_workers = 2
)

Fashion MNIST를 사용자의 폴더 내에 다운로드해준다.

Autoencoder에서 optimizer로 Adam, 그리고 손실값으로는 MSELoss를 사용했다.

Epoch 1~3 and Epoch 8~10

Last updated

Was this helpful?