지금까지는 매우 일반적인 기본 코드를 직접 작성했습니다. 하지만 사실 파이토치는 이런 구현
을 쉽게 해주는 유용한 클래스를 제공합니다. 가장 먼저 시도할만한 일은
linear1
함수를 파
이토치의
nn
.
Linear
모듈로 대체하는 것입니다.
module
이란 파이토치의
nn
.
Module
클
래스를 상속받은 클래스 객체를 의미합니다. 이 클래스의 객체는 일반적인 파이썬 함수와 작
동 방식이 같습니다. 즉 소괄호로 호출할 수 있으며, 호출 결과로 모델의 출력 활성값을 반환합
니다.
nn
.
Linear
는 앞서 만든
init
_
params
및
linear
의 작동을 하나로 수행합니다. 단일 클래스
내에
와
모두가 저장되죠. 앞 절에서 만든 모델을
nn
.
Linear
로 다음과 같이 만들
수 있습니다.
linear_model=nn.Linear(28*28,1)
모든 파이토치의 모듈은 학습할 수 있는 파라미터의 존재를 자체적으로 알고 있습니다. 파라미
터 목록은
parameters
메서드로 접근할 수 있습니다.
>>> w,b=linear_model.parameters()
>>> w.shape,b.shape
(torch.Size([1, 784]), torch.Size([1]))
그리고 이 파라미터 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.