분류 전체보기(79)
-
[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 -
[Pytorch 기초 - 1] Pytorch의 가장 기본적인 함수들
PyTorch Basic¶ PyTorch 기초 사용법 In [1]: import numpy as np import torch In [2]: torch.__version__ Out[2]: '1.6.0' In [3]: nums = torch.arange(9) nums Out[3]: tensor([0, 1, 2, 3, 4, 5, 6, 7, 8]) In [4]: nums.shape Out[4]: torch.Size([9]) In [5]: type(nums) Out[5]: torch.Tensor In [6]: nums.numpy() Out[6]: array([0, 1, 2, 3, 4, 5, 6, 7, 8], dtype=int64) In [7]: nums.reshape(3,3) Out[7]: tensor([[0, ..
2020.09.01 -
[tensorflow2.x 기초 - 6] MNIST data로 Evaluation & Prediction을 구현기본
TensorFlow: Evaluating & Prediction¶ In [1]: import tensorflow as tf from tensorflow.keras import layers from tensorflow.keras import datasets Build Model¶ In [2]: input_shape = (28, 28, 1) num_classes = 10 learning_rate = 0.001 In [3]: inputs = layers.Input(input_shape) net = layers.Conv2D(32, (3, 3), padding='SAME')(inputs) net = layers.Activation('relu')(net) net = layers.Conv2D(32, (3, 3), p..
2020.09.01