하루 하루
펭귄브로의 3분 딥러닝 파이토치맛 _ 5일차 본문
ResNet
마이크로소프트에서 개발된 ResNet은 2015년 ILSVRC에서 우승을 차지한 알고리즘
ResNet 이 기존 모델과 다른 점은 Shortcut 이 있다는 것이다.
Shortcut은 신경망에서 input data를 몇 계층씩 건너뛰어서
output에 더할 수 있도록 해 입력의 특징이 유실되지 않도록 해준다.
CIFAR -10 데이터셋
https://www.cs.toronto.edu/~kriz/cifar.html
CIFAR-10 데이터 세트는 10 개 클래스의 60000 32x32 컬러 이미지와 클래스 당 6000 개의 이미지로 구성된다.
50000 개의 훈련 이미지와 10000 개의 테스트 이미지가 있다.
해당 데이터셋은 컬러 이미지를 포함하고 있는데, 컬러 이미지는 몇 가지 채널을 포함한다.
CNN 코드
Input 이 들어오면 위와 같은 프로세스를 거친다.
layer의 내부 구조는 다음 그림과 같으며 각 layer는 2개의 Residual 블록을 가지고 있다.
주의할 점은 layer1 에서는 shortcut이 없으나
layer2 와 layer3에서는 shortcut이 있다는 점이ㅏ.
(* 그와 같이 설계한 이유는 찾아 볼 것! 혹시 아시는 분 계시면 댓글로 달아주세요. )
**** 실행 오류 발견 ****
1
2
3
4
5
6
7
8
|
for epoch in range(1, EPOCHS+1):
scheduler.step()
train(model, train_loader, optimizer, epoch)
test_loss, test_accuracy = evaluate( model, test_loader )
print('[{}] Test Loss : {:.4f}, Accuracy: {:.2f}%'
.format( epoch, test_loss, test_accuracy))
|
cs |
책에서 실행코드가 위와 같이 scheduler.step() 다음에 train(model, train_loader, optimizer, epoch) 가 실행되도록 되어 있다. 이 경우 아래와 같은 오류가 발생한다.
1
2
3
4
5
6
7
|
UserWarning: Detected call of lr_scheduler.step() before optimizer.step().
In PyTorch 1.1.0 and later, you should call them in the opposite order: optimizer.step() before lr_scheduler.step().
Failure to do this will result in PyTorch skipping the first value of the learning rate schedule.
#how-to-adjust-learning-rate "https://pytorch.org/docs/stable/optim.html#how-to-adjust-learning-rate", UserWarning)
|
https://pytorch.org/docs/stable/optim.html#how-to-adjust-learning-rate
torch.optim — PyTorch master documentation
torch.optim torch.optim is a package implementing various optimization algorithms. Most commonly used methods are already supported, and the interface is general enough, so that more sophisticated ones can be also easily integrated in the future. How to us
pytorch.org
해당 사이트를 접속해보면 다음과 같이 코드가 나온다. 보면 train 다음에 scheduler.step() 이 나오는 것을 확인할 수 있다.
따라서, 코드를 실행시키기 위해서 아래와 같이 train ( ) 과 scheduler.step( ) 의 위치를 바꾸었다.
1
2
3
4
5
6
7
8
|
for epoch in range(1, EPOCHS+1):
train(model, train_loader, optimizer, epoch)
scheduler.step()
test_loss, test_accuracy = evaluate( model, test_loader )
print('[{}] Test Loss : {:.4f}, Accuracy: {:.2f}%'
.format( epoch, test_loss, test_accuracy))
|
cs |
실행 화면
'IT > Artificial intelligence' 카테고리의 다른 글
펭귄브로의 3분 딥러닝 파이토치맛_6일차 (0) | 2020.04.22 |
---|---|
Batch Normalization ( 배치 정규화 ) (0) | 2020.04.20 |
펭귄브로의 3분 딥러닝 파이토치맛 _ 4일차 (0) | 2020.04.19 |
펭귄브로의 3분 딥러닝 파이토치맛 _ 3일차 (0) | 2020.04.17 |
TORCH.NN (0) | 2020.04.17 |