티스토리 뷰
Tensorflow 2.0 - AttributeError: module 'tensorflow' has no attribute 'Session' 에러 수정하기
맨날치킨 2022. 12. 6. 19:05Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.
Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.
아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.
Tensorflow 2.0 - AttributeError: module 'tensorflow' has no attribute 'Session'
Tensorflow 2.0 - AttributeError: module 'tensorflow' has no attribute 'Session' 에러 수정하기
문제 내용
When I am executing the command sess = tf.Session()
in Tensorflow 2.0 environment, I am getting an error message as below:
sess = tf 명령을 실행할 때.Tensorflow 2.0 환경에서 Session()에 다음과 같은 오류 메시지가 표시됩니다.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute 'Session'
System Information:
시스템 정보:
- OS Platform and Distribution: Windows 10
- Python Version: 3.7.1
- Tensorflow Version: 2.0.0-alpha0 (installed with pip)
OS 플랫폼 및 배포: 윈도우 10
파이썬 버전: 3.7.1
Tensorflow 버전: 2.0.0-alpha0(파이프 포함)
Steps to reproduce:
Installation:
재현 단계:
설치:
- pip install --upgrade pip
- pip install tensorflow==2.0.0-alpha0
- pip install keras
- pip install numpy==1.16.2
Execution:
실행:
- Execute command: import tensorflow as tf
- Execute command: sess = tf.Session()
명령 실행: tensorflow를 tf로 가져오기
명령 실행: sess = tf.세션()
높은 점수를 받은 Solution
According to TF 1:1 Symbols Map
, in TF 2.0 you should use tf.compat.v1.Session()
instead of tf.Session()
TF 1:1 심볼 맵에 따르면 TF 2.0에서 tf.Session() 대신에 tf.compat.v1.Session()을 사용해야 합니다.
https://docs.google.com/spreadsheets/d/1FLFJLzg7WNP6JHODX5q8BDgptKafq_slHpnHVbJIteQ/edit#gid=0
https://docs.google.com/spreadsheets/d/1FLFJLzg7WNP6JHODX5q8BDgptKafq_slHpnHVbJIteQ/edit#gid=0
To get TF 1.x like behaviour in TF 2.0 one can run
TF 2.0에서 TF 1.x와 같은 동작을 얻으려면 실행할 수 있습니다.
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
but then one cannot benefit of many improvements made in TF 2.0. For more details please refer to the migration guide https://www.tensorflow.org/guide/migrate
그러나 TF 2.0에서 이루어진 많은 개선의 혜택을 받을 수는 없다. 자세한 내용은 마이그레이션 가이드를 참조하십시오. https://www.tensorflow.org/guide/migrate
가장 최근 달린 Solution
For Tensorflow 2.0 and later, try this.
Tensorflow 2.0 이상의 경우, 이것을 사용해 보세요.
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
a = tf.constant(5)
b = tf.constant(6)
c = tf.constant(7)
d = tf.multiply(a,b)
e = tf.add(c,d)
f = tf.subtract(a,c)
with tf.compat.v1.Session() as sess:
outs = sess.run(f)
print(outs)
출처 : https://stackoverflow.com/questions/55142951/tensorflow-2-0-attributeerror-module-tensorflow-has-no-attribute-session
'개발 > 파이썬' 카테고리의 다른 글
Pandas DataFrame 열 전체 리스트 가져오기 (0) | 2022.12.06 |
---|---|
데이터 프레임 열 순서 변경하기 (0) | 2022.12.06 |
딕셔너리 복사 후 사본만 편집하기 (0) | 2022.12.06 |
Python을 사용하여 리스트 내용을 파일에 쓰기 (0) | 2022.12.06 |
비어 있지 않은 폴더 삭제하기 (0) | 2022.12.06 |