pytorch(35)
-
[TIP / Installation] requirements.txt 로 pytorch package 설치하는 방법
보통 다른 패키지들은 아래와 같은 freeze를 이용해서 파일을 하나 생성하고 설치하면 정상적으로 설치가 된다. pip freeze > requirements.txt pip install -r requirements.txt 보통 requirements.txt 파일은 아래와 같이 생성된다. scikit-learn==0.23.2 scipy==1.5.3 seaborn==0.11.0 shap==0.36.0 six==1.15.0 slicer==0.0.4 statsmodels==0.12.0 tabulate==0.8.7 threadpoolctl==2.1.0 torch==1.6.0+cpu torchvision==0.7.0+cpu 하지만 이렇게 해서 설치를 하면, torch를 설치할 때 에러가 발생하게 된다. 그래서 검..
2020.10.25 -
[TIP / Pytorch] Linear NN Model base Architecture
pytorch가 arhcitecture가 저장이 안 되니, 본 판때기를 잘 만들어서 한 구조에서 여러개의 파리미터를 넣을 수 있도록 해야 한다. 여기서는 본 판때기에 대한 base를 만들어봄. from torch import nn class Net(nn.Module) : def __init__(self, layers , activation, bn, dropout) : super(Net,self).__init__() self.model = self.make_model(layers , activation, bn, dropout) def forward(self, x) : self.model(x) def make_model(self, layers , activation, bn, dropout) : model =..
2020.10.23 -
[Pyro] Bayesian Regression 해보기
pyro.ai/examples/bayesian_regression.html Bayesian Regression - Introduction (Part 1) — Pyro Tutorials 1.4.0 documentation Model In order to make our linear regression Bayesian, we need to put priors on the parameters \(w\) and \(b\). These are distributions that represent our prior belief about reasonable values for \(w\) and \(b\) (before observing any data). Making a Bayesi pyro.ai pytorch에서 ..
2020.09.29 -
[skorch] VAE 적용 구현해보기
base.py ( vae_models 폴더 안에) from .types_ import * from torch import nn from abc import abstractmethod class BaseVAE(nn.Module): def __init__(self) -> None: super(BaseVAE, self).__init__() def encode(self, input: Tensor) -> List[Tensor]: raise NotImplementedError def decode(self, input: Tensor) -> Any: raise NotImplementedError def sample(self, batch_size:int, current_device: int, **kwargs) -> Te..
2020.09.22 -
[Pytorch] torch에서 모델 summary 확인하는 방법
pytorch에서 keras처럼 summary를 정리해주는 함수가 있어서 공유한다. 찾다 보면 좋은 툴이 많은 것 같다(굳굳) Keras처럼 파라미터 개수랑 용량을 제공해준다! import torch from torch import nn from torchsummary import summary as summary_ from torch.nn import functional as F class MnistModel(nn.Module): def __init__(self): super(MnistModel, self).__init__() # input is 28x28 # padding=2 for same padding self.conv1 = nn.Conv2d(1, 32, 5, padding=2) # feature..
2020.08.25 -
[Pytorch] Pytorch를 Keras처럼 API 호출 하는 방식으로 사용하는 방법
파이토치에서 케라스처럼 API를 만들어서 하는 경우를 발견하게 돼서 공유한다. 실제로 이 규격에 맞춰서 LSTM도 만들수도 있을 것 같다(조금 복잡할 것 같기도 하지만) 기존 코드를 조금씩 바꿔서 해봤고, 아래에는 Custom Dataset에 대해서 새로 만들어서 진행해봤다. 이런 좋은 코드를 공유해주신 다른 분들이 고맙고, 나도 조금 수정을 해서 공유를 한다. 다들 즐거운 코딩하시길! Library Load import torch from torch import nn from torch import optim from torch.autograd import Variable from torchsummary import summary as summary_ import pkbar import warnings..
2020.08.25 -
[Pytorch] LSTM AutoEncoder for Anomaly Detection
LSTM AutoEncoder를 사용해서 희귀케이스 잡아내기 LSTM AutoEncoder를 사용해서 희귀케이스 잡아내기 도움이 되셨다면, 광고 한번만 눌러주세요. 블로그 관리에 큰 힘이 됩니다 ^^ 우리 데이터는 많은데, 희귀 케이스는 적을 때 딥러닝 방법을 쓰고 싶을 때, AutoEncoder를 사용해서 희귀한 것에 대해�� data-newbie.tistory.com 기존에는 LSTM AutoEncoder에 대한 설명이라면, 이번에는 Pytorch로 구현을 해보고자 했다. 물론 잘못된 것이 있을 수 있으니, 피드백 주면 수정하겠다. Anomaley Detection을 당일날 맞추면 의미가 없으므로 시점을 이동시키는 작업을 하고, 이동시킨 데이터를 이용해 LSTM AutoEncoder를 진행해보고자 한..
2020.08.23 -
[Pytorch] MixtureSameFamily 을 사용해서 bimodal distribution 만들기
torch 1.5.0 버전부터 생김 bimodal gaussian distribution 만들기 n = 1000 import torch import seaborn as sns from torch.distributions import Normal from torch import distributions as D from torch.distributions.mixture_same_family import MixtureSameFamily d = torch.cat((Normal(loc=-3, scale =1.0).sample((n,1)) , Normal(loc=0.5, scale =1.0).sample((n,1))),dim=1) mix = D.Categorical(probs = torch.nn.Softmax()..
2020.05.05 -
[Pytorch] 1.5.0 버전 설치하기
(20.05.05 기준) pytorch에서 mixture_same_family를 사용하고 싶은데, 1.5.0 버전에서만 지원이 되는 것을 확인하였다. 그래서 찾다보니 아래 사이트에서 알려주는 방법으로 일단 설치를 하려고 하니 자꾸 1.4.0이 설치가 되려고 한다. conda install pytorch torchvision cpuonly -c pytorch https://pytorch.org/ PyTorch An open source deep learning platform that provides a seamless path from research prototyping to production deployment. pytorch.org 그래서 필자는 anaconda 환경을 쓰고 있고 anaconda의..
2020.05.05 -
BLiTZ — A Bayesian Neural Network LSTM 으로 주가 예측 해보기
광고 한 번씩 눌러주세요! 블로그 운영에 큰 힘이 됩니다 :) 이번엔 BLiTZ 개발자가 LSTM을 베이지안 뉴럴 네트워크로 구현해줬다. 요즘 LSTM 쪽을 공부하고 있는데, 또 하나의 선택지로 고민해볼 만한 것 같아서 해보기로 했다. BLiTZ 개발자는 종가 데이터만을 넣고 하루 뒤 종가를 예측하는 것을 예제로 보여줬고, 필자는 'Open', 'High', 'Low', 'Close', 'Volume' 총 5가지 input을 주고 하루 뒤 Close를 예측하는 것을 해봤다. 우리가 알고 있는 LSTM의 형태이다. 여기서 W,Bias를 determinstic 하게 사용하지 않고 분포에서 샘플링으로 하는 것이 이 패키지의 베이지안 방법이다. ## Data Normalizing scaler = Standard..
2020.04.19 -
PyTorch에서 SHAP을 사용하여 모델 해석하기 (정형 데이터)
Torch를 프레임워크를 사용한 Neural Network를 eXAI 알고리즘 중 하나인 SHAP을 사용해서 적용해보기 import torch, torchvision from torchvision import datasets, transforms from torch import nn, optim from torch.nn import functional as F import numpy as np import shap import pandas as pd Myutils는 개인적으로 분석하면서 모아놓은 모음집 from Myutils import * from sklearn.compose import ColumnTransformer from sklearn.pipeline import Pipeline 데이터 간단한 ..
2020.03.14