model.load() 시 AttributeError: 'str' object has no attribute 'decode' 에러

2023. 4. 17. 14:43Tensorflow

(요약) tensorflow 와 h5py 버전이 맞지 않아서 발생함.

pip or conda 패키지 채널을 확인 후 라이브러리 버전을 맞출 것.

ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

 

우선, 모델 load 시 AttributeError: 'str' object has no attribute 'decode' 에러가 발생한다면

이는 h5py 버전이 tensorflow와 맞지 않아 발생한 문제이다.

 

tensorflow 1.14 버전 기준 h5py==2.10.0 으로 맞추어주면 동작하게 되는데, 많은 곳에서 해당 에러를 검색할 경우

pip uninstall h5py

pip install h5py

 

과 같이 h5py 라이브러리를 삭제 후 재설치하여 해결했다고 알려준다.

 

하지만 다음과 같이 진행시 tensorflow가 같이 삭제된다.... 응?

tensorflow를 다시 깔아주고.. 실행시 밑 내용과 같은 에러를 다시 마주하게 되는데,,,,

 

Warning! ***HDF5 library version mismatched error***
The HDF5 header files used to compile this application do not match
the version used by the HDF5 library to which this application is linked.
Data corruption or segmentation faults may occur if the application continues.
This can happen when an application was compiled by one version of HDF5 but
linked with a different version of static or shared HDF5 library.
You should recompile the application or check your shared library related
settings such as 'LD_LIBRARY_PATH'.
You can, at your own risk, disable this warning by setting the environment
variable 'HDF5_DISABLE_VERSION_CHECK' to a value of '1'.
Setting it to 2 or higher will suppress the warning messages totally.
Headers are 1.10.4, library is 1.10.5

...

Bye...

 

h5py 버전 안맞아서 다시 깔고, tensorflow 삭제되서 다시 깔았는데,,, 버전이 둘이 또 안맞다고 한다.

(핵심은 라이브러리 패키지 관리 채널이 다름을 인지하게 올바르게 명령어를 입력해야하는 것이다)

 

가상환경을 사용하고 있을 경우 conda 로 명령어를 보통 입력할 것이다.

conda list 를 이용하여 라이브러리 목록을 확인해보자.

h5py==2.10.0 버전으로 해결하였는데 이는 tensorflow 버전에 따라 호환되는 버전이 다르니 확인해보자

(본인은 tensorflow 1.14 버전)

 

conda list 출력 시 h5py 라이브러리의 Channel 열에 해당하는 부분에 pypi 라고 적혀있는 것을 확인할 수 있다.

이는 라이브러리 패키지 관리 채널이 pypi, 즉 pip라는 소리이다.

 

무슨소리냐? 패키지 관리 매니저는 pip, pip3, 그리고 아나콘다를 사용한다면 conda 까지 여러 종류가 있는데 해당 채널이 무엇인지 알려주는 것이다.

 

따라서.... conda list로 출력했음에도 h5py 라이브러리를 업데이트,삭제하기 위해서는 pip 명령어를 사용해야 한다는 것이다.

 

pip 를 이용하여 h5py 라이브러리 설치

pip 명령어를 이용하니 라이브러리 버전을 수정할 수 있었고, 패키지 매니저도 conda로 수정됨을 확인할 수 있다.