일단, 각 레이어에 저장되어 있는 input_shape 값을 통해 가중치를 생성해보자. 너무 복잡하네
# build 와 함께 가중치 초기화
def build(self, input_shape=None):
#input_shape = input_shape
if not self._layers:
raise ValueError(
f"Sequential model {self.name} cannot be built because it has "
"no layers. Call `model.add(layer)`."
)
if isinstance(self._layers[0], InputLayer):
input_shape = self._layers[0].input_shape
# 가중치 초기화만 시행할거야
for layer in self._layers[1:]:
try:
# build 메서드 실행, input_shape 와 해당 layer의 output_shape 크기
# 를 통해 임의의 가중치가 생성된다.
# 생성된 가중치는 해당 레이어 인스턴스에 저장,
layer.build(input_shape)
input_shape = layer.output_shape
except NotImplementedError:
return
self.built = True
Sequential class 의 build 메서드의 내용,
각 레이어의 build 메서드 실행, 해당 인스턴스에 가중치 값이 저장된다.
'ml_interview' 카테고리의 다른 글
가우시안 분포 (0) | 2024.11.25 |
---|---|
베이지안 확률 (0) | 2024.11.25 |
라그랑주 승수법 (0) | 2024.08.27 |
Early Stopping - 모형의 유효 수용력 model capacity, 가중치 감쇄와 조기 종료의 동치성, 상호 보완, (0) | 2024.08.22 |
semi-supervised learning (0) | 2024.08.22 |