일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- LG디스플레이
- aws
- sk
- awscloud
- DT
- lg인성검사
- awscloudbootcamp
- sktai
- awsacademy
- lgenius
- lg인적성합격
- lg인재상
- cloudarchitecting
- LGD
- e1인턴
- 2022awscloudbootcamp
- lg디스플레이산학장학생
- 2022awscloud
- SKT
- cloudfoundations
- SK인턴
- aws클라우드부트캠프
- lg합격
- lg인적성모의고사
- SKC&C
- 데이터분석
- LG인적성후기
- lg적성검사
- LG인적성
- lg디스플레이lgenius
Archives
- Today
- Total
냥냥파워
Image Classification with ResNet50 in Pytorch 본문
https://blog.devgenius.io/resnet50-6b42934db431
ResNet50
ResNet-50 is a convolutional neural network that is 50 layers deep. ResNet, short for Residual Networks is a classic neural network used as…
blog.devgenius.io
1. set env
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
import os
import torch
import torchvision
from torchvision import datasets, models, transforms
import torch.nn as nn
from torch.nn import functional as F
import torch.optim as optim
import os
os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"]="0"
2. data generator
normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225])
data_transforms = {
'train':
transforms.Compose([
transforms.Resize((224,224)),
transforms.RandomAffine(0, shear=10, scale=(0.8,1.2)),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
normalize
]),
'val':
transforms.Compose([
transforms.Resize((224,224)),
transforms.ToTensor(),
normalize
]),
# 'test':
# transforms.Compose([
# transforms.Resize((224,224)),
# transforms.ToTensor(),
# normalize
# ]),
}
input_path = 'D:/0616dataset/split9'
image_datasets = {
'train':
datasets.ImageFolder(input_path + '/train', data_transforms['train']),
'val':
datasets.ImageFolder(input_path + '/val', data_transforms['val']),
# 'test':
# datasets.ImageFolder(input_path + 'test', data_transforms['test'])
}
dataloaders = {
'train':
torch.utils.data.DataLoader(image_datasets['train'],
batch_size=32,
shuffle=True,
num_workers=0),
'val':
torch.utils.data.DataLoader(image_datasets['val'],
batch_size=32,
shuffle=False,
num_workers=0),
# 'test':
# torch.utils.data.DataLoader(image_datasets['test'],
# batch_size=32,
# shuffle=False,
# num_workers=0)
}
3. set gpu device
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
device
4. load pretrained resnet50
model = models.resnet50(pretrained=True).to(device)
for param in model.parameters():
param.requires_grad = False
model.fc = nn.Sequential(
nn.Linear(2048, 128),
nn.ReLU(inplace=True),
nn.Linear(128, 1253)).to(device)
BIG