본문 바로가기

implement_ml_models/CNN

implement_CNN(MLP_weight_update)

2023.03.12 - [분류 전체보기] - implement_CNN(back_propagation)

 

implement_CNN(back_propagation)

2023.03.10 - [분류 전체보기] - implement_CNN(MLP) implement_CNN(MLP) 2023.03.09 - [분류 전체보기] - implement_CNN(MLP 전 까지) implement_CNN(MLP 전 까지) 2023.03.09 - [분류 전체보기] - implement_CNN(수정) implement_CNN(수정) 202

teach-meaning.tistory.com

역전파법을 통해 계산한 delta 값을 통해 가중치 업데이트를 진행할 수 있다.

계산한 delta 값에 각 노드 출력과의 연산을 통해 가중치 변화량을 계산할 수 있다.

  def weight_update(self, learning_rate):
    # 연산의 편리함을 위해 뒤집어준다.
    self.delta = self.delta[::-1]
    for i in range(len(self.weight)):
      self.weight_update_arr.append(self.delta[i+1] @ self.node_output[i].T)

      self.weight[i] = self.weight[i] - self.weight_update_arr[i]
  def cal_weight_update_mlp(self, learning_rate):
    self.mlp.weight_update(learning_rate)

거꾸로 계산된 delta 를 뒤집고, 이전 층의 출력을 통해 가중치 업데이트 량을 계산하고, 학습률을 곱해 가중치를 갱신한다.

cnn.cal_weight_update_mlp(0.1)

cnn.mlp.weight_update_arr[1].shape
>>>
(64, 128)

가중치 모양의 확인, 가중치 업데이트의 수행

'implement_ml_models > CNN' 카테고리의 다른 글

implement_CNN(CNN_backpropagation_pooing)  (0) 2023.03.15
implement_CNN(CNN_backpropagation)  (0) 2023.03.14
implement_CNN(back_propagation)  (0) 2023.03.12
implement_CNN(MLP)  (0) 2023.03.10
implement_CNN(MLP 전 까지)  (0) 2023.03.09