JuJuKwakKwak

keras 버전 / 설치 관련 에러 본문

Data Science/error 모음

keras 버전 / 설치 관련 에러

jujukwakkwak 2022. 3. 29. 09:03

[1] 첫 번째 문제

import keras

위의 코드를 쳤더니 다음의 메시지가 뜬다.

module 'keras.engine.base_layer' has no attribute 'BaseRandomLayer'

 

그래서 아나콘다 프롬프트를 켜서

1) pip uninstall keras 쳤다.

2) 마우스로 직접 keras 폴더 삭제 (폴더 경로 : C 드라이브 -> 사용자 -> anaconda3 -> site-packages

3) pip install keras 쳤다.

 

다시 동일한 코드를 쳤더니 다음의 메시지가 뜬다.

module 'tensorflow.compat.v2.__internal__' has no attribute 'register_clear_session_function'

import tensorflow.keras

그냥 keras가 아니라 tensorflow.keras로 변경해보았다.

무사히 작동되었다.


[2] 두 번째 문제

from keras.utils import np_utils

위의 코드를 쳤더니 다음의 메시지가 뜬다.

cannot import name 'np_utils' from 'tensorflow.keras.utils'

 

그래서 아나콘다 프롬프트를 열어서

pip install np_utils 쳤다.

 

import np_utils

위의 코드를 쳤더니 무사히 작동되었다.


[3] 세 번째 문제

Y_train = np_utils.to_categorical(Y_train)

위의 코드를 쳤더니 다음의 메시지가 뜬다.

module 'np_utils' has no attribute 'to_categorical'

 

from tensorflow.keras.utils import to_categorical
Y_train = to_categorical(Y_train)

위의 코드로 쳤더니 무사히 작동되었다.