목록pytorch (16)
rueki

이번에는 Convolution Neural Network를 이용해서 MNIST Classification을 진행해보자. 1. 라이브러리 호출 import torch import torch.nn as nn import torch.nn.functional as F from torch.utils.data import DataLoader from torchvision import datasets, transforms from torchvision.utils import make_grid import numpy as np import pandas as pd from sklearn.metrics import confusion_matrix import warnings import matplotlib.pyplot as..

이번에는 ANN을 이용해서 MNIST 이미지를 분류해보는 모델을 만들어보자. 파이토치에는 비젼분야를 위한 torchvision이 있어서 매우 용이하다. import torch import torch.nn as nn import torch.nn.functional as F from torch.utils.data import DataLoader from torchvision import datasets, transforms import numpy as np import pandas as np from sklearn.metrics import confusion_matrix import matplotlib.pyplot as plt %matplotlib inline 앞서 작성한 글에서도 언급했듯이, 어떤 데이터가..

import torch import numpy as np import matplotlib.pyplot as plt import torch.nn.functional as F # ANN 모델 생성 class Model(nn.Module): def __init__(self, in_features=4, h1 =8,h2=9, out_features=3): super().__init__() self.fc1 = nn.Linear(in_features, h1) self.fc2 = nn.Linear(h1,h2) self.out = nn.Linear(h2, out_features) # 입력 -> 은닉층 1 -> 은닉층 2 -> 출력 #순전파 def forward(self, x): x = F.relu(self.fc1(x))..

import torch import numpy as np import matplotlib.pyplot as plt %matplotlib inline import torch.nn as nn X = torch.linspace(1,50,50).reshape(-1,1) # 1부터 50까지 50 step # 크기에 맞춰서 1열 형태로 X ''' tensor([[ 1.], [ 2.], [ 3.], [ 4.],...... ''' torch.manual_seed(71) e = torch.randint(-8,9,(50,1), dtype=torch.float) # error 값, -8부터 9 까지 50 x 1 크기로 y = 2*X + 1 + e #함수 정의 plt.scatter(X.numpy(),y.numpy()) tor..