AttributeError: module 'tensorflow' has no attribute 'contrib'

2021. 5. 25. 14:28문제들

요약 : tensorflow1이 필요한 코드가 아닌 경우 고려할 필요없다.

발생 - hyper parameter 조정시 필요

Traceback (most recent call last):
  File "preprocess.py", line 15, in <module>
    from hparams import hparams, hparams_debug_string
  File "/content/Tacotron2-Wavenet-Korean-TTS/hparams.py", line 6, in <module>
    hparams = tf.contrib.training.HParams(
AttributeError: module 'tensorflow' has no attribute 'contrib'

 

 

 

 

https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md

https://tensorflowkorea.gitbooks.io/tensorflow-kr/content/g3doc/tutorials/tflearn/

tf.contrib

  • 커뮤니티 멤버가 tensorflow 오픈소스에 기여, 테스트할 수 있게끔 해주는 모듈.
  • tensorflow의 실험적인 기능을 제공
  • tensorflow 2 에서 만료됨

 

 

tf1 -> tf2로 코드 업그레이드

tf_upgrade_v2 --infile hparams.py --outfile hparams_copy.py

 

 

결과 - 실패

ERROR line 6:10: Using member tf.contrib.training.HParams in deprecated module tf.contrib. tf.contrib.training.HParams cannot be converted automatically. tf.contrib will not be distributed with TensorFlow 2.0, please consider an alternative in non-contrib TensorFlow, a community-maintained repository such as tensorflow/addons, or fork the required code.
TensorFlow 2.0 Upgrade Script
-----------------------------
Converted 1 files
Detected 1 issues that require attention
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
File: hparams.py
--------------------------------------------------------------------------------
hparams.py:6:10: ERROR: Using member tf.contrib.training.HParams in deprecated module tf.contrib. tf.contrib.training.HParams cannot be converted automatically. tf.contrib will not be distributed with TensorFlow 2.0, please consider an alternative in non-contrib TensorFlow, a community-maintained repository such as tensorflow/addons, or fork the required code.


Make sure to read the detailed log 'report.txt'

 

 

 

 

https://github.com/tensorflow/tensorflow/issues/39768

python 3.8 사용시 tf 2.2 이상 버전을 지원한다. 1.x 버전에 대한 pip 패키지 지원은 없다.

tf 1.15 사용시 python3.7 이하 버전이 필요하기 때문에 해당 버전의 python으로 환경을 구성해야한다.