반응형
[PyTorch] Evaluating 및 Predicting
IT/AI2022. 9. 13. 16:16[PyTorch] Evaluating 및 Predicting

이전 블로그를 이어서 진행을 합니다. Evaluation model.train() 모드로 변한 것 처럼 평가할 때는 model.eval() 으로 설정합니다. # Test mode # batch norm이나 dropout 등을 train mode 변환 model.eval() # Out Net( (conv1): Conv2d(1, 20, kernel_size=(5, 5), stride=(1, 1)) (conv2): Conv2d(20, 50, kernel_size=(5, 5), stride=(1, 1)) (fc1): Linear(in_features=800, out_features=500, bias=True) (fc2): Linear(in_features=500, out_features=10, bias=True..

[PyTorch] Optimizer 및 Training
IT/AI2022. 9. 13. 16:03[PyTorch] Optimizer 및 Training

Optimization & Training https://github.com/pytorch/examples/tree/master/mnist Load Packages 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 no_cuda = False # cuda를 사용할지 안할지 use_cuda = not no_cuda and torch.cuda.is_available() device = torch.device("cuda" if use_cuda else "cpu") => devic..

[PyTorch] 각 Layer별 역할 및 파라미터
IT/AI2022. 9. 13. 14:10[PyTorch] 각 Layer별 역할 및 파라미터

PyTorch Layer 이해하기 Load Packages import torch from torchvision import datasets, transforms import numpy as np import matplotlib.pyplot as plt %matplotlib inline 예제 불러오기 train_loader = torch.utils.data.DataLoader( datasets.MNIST('dataset', train=True, download=True, transform=transforms.Compose([ transforms.ToTensor() ])), batch_size=1) image, label = next(iter(train_loader)) image.shape, label.s..

[PyTorch] 데이터 불러오기
IT/AI2022. 9. 13. 13:18[PyTorch] 데이터 불러오기

PyTorch Data Preprocess import torch from torchvision import datasets, transforms Import Error ImportError: cannot import name 'PILLOW_VERSION' from 'PIL' pillow 버전이 7.0.0 이상 일경우 Import 에러 나는 경우가 있습니다. 아래 처럼 pillow 버전을 내려주면 해결이 됩니다. $ pip install pillow==6.2.2 Data Loader 부르기 Pytorch는 DataLoader를 불러 model에 넣습니다. batch_size = 32 train_loader = torch.utils.data.DataLoader( datasets.MNIST('dataset/..

TensorFlow 2.0과 PyTorch 비교
IT/AI2022. 9. 13. 11:31TensorFlow 2.0과 PyTorch 비교

TensorFlow 2.0 import tensorflow as tf from tensorflow.keras import layers from tensorflow.keras import datasets Hyperparameter batch_size = 64 learning_rate = 0.001 dropout_rate = 0.7 input_shape = (28, 28, 1) num_classes = 10 Preprocess (train_x, train_y), (test_x, test_y) = datasets.mnist.load_data() train_x = train_x[..., tf.newaxis] test_x = test_x[..., tf.newaxis] train_x = train_x / 255. ..

[PyTorch] 기초 사용법
IT/AI2022. 9. 10. 22:19[PyTorch] 기초 사용법

Load Packages import numpy as np import torch Basic PyTorch 기초 사용법 nums = torch.arange(9) nums.shape nums.numpy() nums.reshape(3, 3) randoms = torch.rand((3, 3)) zeros = torch.zeros((3, 3)) ones = torch.ones((3, 3)) torch.zeros_like(ones) Operations PyTorch로 수학연산 하기 nums * 3 nums = nums.reshape((3, 3)) nums + nums result = torch.add(nums, 10) result.numpy() # Out array([[10, 11, 12], [13, 14, 15..

[TensorFlow 2.0] Evaluating & Prediction
IT/AI2022. 9. 10. 21:44[TensorFlow 2.0] Evaluating & Prediction

Load Packages import tensorflow as tf from tensorflow.keras import layers from tensorflow.keras import datasets Build Model input_shape = (28, 28, 1) num_classes = 10 learning_rate = 0.001 inputs = layers.Input(input_shape, dtype=tf.float64) net = layers.Conv2D(32, (3, 3), padding='SAME')(inputs) net = layers.Activation('relu')(net) net = layers.Conv2D(32, (3, 3), padding='SAME')(net) net = laye..

[TensorFlow 2.0] Optimizer 및 Training (Expert)
IT/AI2022. 9. 8. 10:18[TensorFlow 2.0] Optimizer 및 Training (Expert)

TensorFlow 공식 홈페이지에서 설명하는 Expert 버전을 사용해봅니다. Load Packages import tensorflow as tf from tensorflow.keras import layers from tensorflow.keras import datasets 학습 과정 돌아보기 Build Model input_shape = (28, 28, 1) num_classes = 10 inputs = layers.Input(input_shape, dtype=tf.float64) net = layers.Conv2D(32, (3, 3), padding='SAME')(inputs) net = layers.Activation('relu')(net) net = layers.Conv2D(32, (3, 3..

[TensorFlow 2.0] Optimizer 및 Training (Keras)
IT/AI2022. 9. 8. 00:39[TensorFlow 2.0] Optimizer 및 Training (Keras)

Load Packages import tensorflow as tf from tensorflow.keras import layers from tensorflow.keras import datasets 학습 과정 돌아보기 Prepare MNIST Datset (train_x, train_y), (test_x, test_y) = datasets.mnist.load_data() Build Model inputs = layers.Input((28, 28, 1)) net = layers.Conv2D(32, (3, 3), padding='SAME')(inputs) net = layers.Activation('relu')(net) net = layers.Conv2D(32, (3, 3), padding='SAME')(..

[TensorFlow 2.0] 각 Layer별 역할 및 파라미터
IT/AI2022. 9. 7. 17:16[TensorFlow 2.0] 각 Layer별 역할 및 파라미터

Load Packages import tensorflow as tf import os import matplotlib.pyplot as plt %matplotlib inline Input Image from tensorflow.keras import datasets (train_x, train_y), (test_x, test_y) = datasets.mnist.load_data() image = train_x[0] # 차원 수 높이기 image = image[tf.newaxis, ..., tf.newaxis] image.shape # Out (1, 28, 28, 1) Feature Extraction Convolution filters: layer에서 나갈 때 몇 개의 filter를 만들 것인지 kern..

반응형
image