pytorch(4)
-
[Pytorch & Tensorflow2.x 기초] CNN 모델로 Pytorch와 Tensorflow2.x의 기본적인 모델 구현 확인하기
TensorFlow 2.0¶ In [1]: import tensorflow as tf from tensorflow.keras import layers from tensorflow.keras import datasets Hyperparameter Tunning¶ In [2]: num_epochs = 1 batch_size = 64 learning_rate = 0.001 dropout_rate = 0.7 input_shape = (28, 28, 1) num_classes = 10 Preprocess¶ In [3]: # data load (train_x, train_y), (test_x, test_y) = datasets.mnist.load_data() In [5]: # 차원 늘리기 train_x = trai..
2020.09.01 -
[Pytorch 기초 - 4] MNIST data를 활용하여 CNN모델의 학습과 Optimizer, Evaluation
PyTorch: Optimization & Training¶ https://github.com/pytorch/examples/tree/master/mnist In [1]: import torch import torch.nn as nn import torch.nn.functional as F import torch.optim as optim from torchvision import datasets, transforms import numpy as np In [2]: seed = 1 # 난수 고정 batch_size = 64 test_batch_size = 64 no_cuda = False In [3]: # gpu 사용? use_cuda = not no_cuda and torch.cuda.is_availa..
2020.09.01 -
[Pytorch 기초 - 3] MNIST data를 활용하여 Pytorch로 CNN모델 구현 기본
PyTorch Layer 이해하기¶ 예제 불러오기¶ In [6]: import torch from torchvision import datasets, transforms In [7]: import numpy as np import matplotlib.pyplot as plt %matplotlib inline In [8]: train_loader = torch.utils.data.DataLoader( datasets.MNIST('dataset', train=True, download=True, transform=transforms.Compose([ transforms.ToTensor() ])), batch_size=1) In [9]: image, label = next(iter(train_loader)) ..
2020.09.01 -
[Pytorch 기초 - 2] MNIST data를 load와 시각화 작업 구현하기
https://github.com/pytorch/examples/tree/master/mnist PyTorch Data Preprocess¶ In [3]: import torch from torchvision import datasets, transforms Data Loader 부르기¶ 파이토치는 DataLoader를 불러 model에 넣음 In [4]: batch_size = 32 test_batch_size = 32 In [10]: train_loader = torch.utils.data.DataLoader( datasets.MNIST('dataset/',train = True,download = True, transform = transforms.Compose([ transforms.ToTenso..
2020.09.01