케라스(Keras)로 텐서플로우(Tensorflow)를 핸들링하는 부분에서 아래와 같은 에러가 발생하였다.
AttributeError Traceback (most recent call last)
<ipython-input-5-2403a058cf71> in <module>
1 # 인공신경망 모델링
----> 2 model = keras.models.Sequential()
3 model.add(keras.layers.Dense(1, input_shape=(1,)))
4 model.compile('SGD', 'mse')
C:\Anaconda3\lib\site-packages\keras\engine\sequential.py in __init__(self, layers, name)
85
86 def __init__(self, layers=None, name=None):
---> 87 super(Sequential, self).__init__(name=name)
88 self._build_input_shape = None
89
C:\Anaconda3\lib\site-packages\keras\legacy\interfaces.py in wrapper(*args, **kwargs)
89 warnings.warn('Update your `' + object_name + '` call to the ' +
90 'Keras 2 API: ' + signature, stacklevel=2)
---> 91 return func(*args, **kwargs)
92 wrapper._original_function = func
93 return wrapper
C:\Anaconda3\lib\site-packages\keras\engine\network.py in __init__(self, *args, **kwargs)
94 else:
95 # Subclassed network
---> 96 self._init_subclassed_network(**kwargs)
97
98 def _base_init(self, name=None):
C:\Anaconda3\lib\site-packages\keras\engine\network.py in _init_subclassed_network(self, name)
292
293 def _init_subclassed_network(self, name=None):
--> 294 self._base_init(name=name)
295 self._is_graph_network = False
296 self._expects_training_arg = has_arg(self.call, 'training')
C:\Anaconda3\lib\site-packages\keras\engine\network.py in _base_init(self, name)
107 if not name:
108 prefix = self.__class__.__name__.lower()
--> 109 name = prefix + '_' + str(K.get_uid(prefix))
110 self.name = name
111
C:\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py in get_uid(prefix)
72 """
73 global _GRAPH_UID_DICTS
---> 74 graph = tf.get_default_graph()
75 if graph not in _GRAPH_UID_DICTS:
76 _GRAPH_UID_DICTS[graph] = defaultdict(int)
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'
원인은 매우 간단하다. 현재 버전과 위 소스 버전이 맞지 않는 것이다. 처음에 keras를 선언할 때, import keras로 심플하게 선언하였지만, 이전 버전에서나 가능한 얘기이고 'get_default_graph' 에러가 발생하면 케라스의 패키지를 변경하는 것을 잊지 말자
import keras 부분을 아래처럼 변경한다
import tensorflow.keras as keras
반응형
'Stackoverflow > Tensorflow' 카테고리의 다른 글
[Tensorflow] Could not load dynamic library 'cudart64_101.dll' (0) | 2020.07.31 |
---|---|
Tensorflow, ImportError: DLL load failed while importing _pywrap_tensorflow_internal (0) | 2020.07.27 |
[Keras] Layer model is not connected, no input to return. (0) | 2020.05.20 |
Tensorflow, ImportError: DLL load failed 에러 (0) | 2020.03.24 |
[Tensorflow] Nan in summary histogram for (0) | 2018.08.21 |