Python 으로 배우는 머신러닝

09 강 정리, softmax classifier

JoyFullM2 2020. 7. 13. 14:23

 

 

이 부분이 잘 이해가 안가...

 

osftmaz -> NLL loss 로 바꿔서 사용할 수 있다.

this is for the input image sizes.

 

 

MINST network

 

 

 

 

이렇게 직접 입력을 해 주는건가?

 

이렇게 network model 을 만든 후에는, 이 model 을 가지고 forward 를 진행한다. ( 학습 )

아 저번에 code 다 적어놨었는데ㅜㅜ그래도 한번 다 적어놨으니까 기억 나겠지?

 

cass Net (nn.Module) :

    def __nit__(self ):

          super(Net, self).__init__()

          self.l1 = nn.Linear(784, 520)

          self.l2 = nn.Linear(520, 320)

          self.l3 = nn.Linear(320, 240)

          self.l4 = nn.Linear(240, 120)

          self.l5 = nn.Linear(120, 10)

 

def forward(self, x ):

        # Flatten the data ( n, 1, 28, 28) -> (n , 784)   // 여기서 말하는 n 은 뭘까

         x = x.view(-1, 784)  // flatten the data

         x = F.relu(self.l1(x))  // layer 

         x = F.relu(self.l2(x))

         x = F.relu(self.l3(x))

         x = F.relu(self.l4(x))

         return self.l5(x) # no need activation -> logit 을 사용.

 

criterion = nn.CrossEntropyLoss() // 우리가 loss function 으로 cross entropy 를 사용할 것임

...

 

for batch_idx , data , target in enumerate (train_loader):    //여기서 말하는 target 이란 뭘까

        data, target = Variable(data), Variable(target )

        optimizer.zero_grad()

        output = model(data)

        loss = criterion (output, target)

        loss.backward()

        optimizer.step()

 

 

 

 

load data -> model -> criterion -> train cycle 

 

         

         predict , given target

 

 

accuracy : devide dataset into two ( trainig and testing ) 

 

 

multiple layer 가 있는 경우 cross entropy 를 사용하라