본문 바로가기
2/[ Python ]

Layer ModuleWrapper has arguments in `__init__` and therefore must override `get_config`

by Kieran_Han 2022. 7. 5.

기존 개발환경

  • Python 3.7.0
  • Tensorflow 2.5.0

위 버전에서 PC 포맷 겸, 버전을 아래와 같이 업그레이드했더니 나타난 에러이다.

  • Python 3.9.0
  • Tensorflow 2.7.0

 

구글링하며, Stackoverflow를 보면, 모두들 하나 같이

def get_config(self):

    config = super().get_config().copy()
    config.update({
        'vocab_size': self.vocab_size,
        'num_layers': self.num_layers,
        'units': self.units,
        'd_model': self.d_model,
        'num_heads': self.num_heads,
        'dropout': self.dropout,
    })
    return config

위 코드를 Class에 넣으라고하는데, 내가 만든 DNN 코드는 class 객체를 사용하지 않아 어떻게 해야하나 싶었다가 나와 같은 고민을 하는 한국분 글을 우연히 봤다.

https://stackoverflow.com/questions/67875727/layer-modulewrapper-has-arguments-in-init-and-therefore-must-override-get/67942707#67942707?newreg=8f62905bc3f443afb6dfc6b5b01c83ea 

 

Layer ModuleWrapper has arguments in `__init__` and therefore must override `get_config`. in Colab

I'm trying to make keras modelcheckpoint code. But Whenever I started the code, that get_config error occured. Below is my keras code. model = keras.Sequential() model.add(keras.layers.Flatten(

stackoverflow.com

 

위 덧글에서와 같이 tensorflow와 tf.keras를 혼용해서 발생하는 에러로 파악하여 코드를 아래와 같이 수정하였더니 에러가 해결되었다.


from tensorflow import keras
from tensorflow.python.keras import layers

↓↓↓

from tensorflow import keras
from tensorflow.keras import layers

위 한 줄 바꿨더니, 잘되더라!