rlcode / reinforcement-learning-kr-v2

[파이썬과 케라스로 배우는 강화학습] 텐서플로우 2.0 개정판 예제
MIT License
126 stars 98 forks source link

model summary 는 어떻게 봐야하나요? #18

Open rubyjohn opened 3 years ago

rubyjohn commented 3 years ago

2-breakout-a3c 에서 train.py 를 해보는 중인데,

self.global_model.summary() 해봤더니 모델 요약 조금 나오다 ValueError: You tried to call count_params on conv2d_2, but the layer isn't built. You can build it manually via: conv2d_2.build(batch_input_shape).

self.local_model.summary() 해봤더니 ValueError: This model has not yet been built. Build the model first by calling build() or calling fit() with some data, or specify an input_shape argument in the first layer(s) for automatic build.

이런 에러가 나오면서 모델 요약을 안보여주는데 어느 부분에서 봐야하나요?

rubyjohn commented 3 years ago

자답합니다. 여러군데 검색한 결과

from tensorflow.keras.layers import Input
from tensorflow.keras.models import Model

class ActorCritic(tf.keras.Model):
    ...
    def model(self):
        x = Input(shape=self.state_size)
        return Model(inputs=[x], outputs=self.call(x))

이렇게 선언한뒤 요약을 봐야하는 곳에서

self.global_model.model().summary()

이런식으로 하면 볼 수 있군요. 다만 저 def model()은 현 상태에서는 오직 요약을 보는 용도이고 따로 쓸데는 없군요. ㅠㅠ