"TensorFlow"의 두 판 사이의 차이

Pywiki
둘러보기로 가기 검색하러 가기
15번째 줄: 15번째 줄:
 
!과정
 
!과정
 
!설명
 
!설명
!방법
 
 
|-
 
|-
 
|사전준비
 
|사전준비
23번째 줄: 22번째 줄:
 
# <code>pip install tensorflow</code>를 할 때 <code>ERROR: Could not find a version that satisfies the requirement tensorflow</code>가 뜬다면 파이썬이 64bit용이 아니기 때문이다.(텐서플로우는 64bit 기반)
 
# <code>pip install tensorflow</code>를 할 때 <code>ERROR: Could not find a version that satisfies the requirement tensorflow</code>가 뜬다면 파이썬이 64bit용이 아니기 때문이다.(텐서플로우는 64bit 기반)
 
# cpu stable 버전이 요구하는 넘파이 버전이 일정 미만일 수 있다.
 
# cpu stable 버전이 요구하는 넘파이 버전이 일정 미만일 수 있다.
|
 
 
|-
 
|-
|
+
|GPU사용준비
|
+
|텐서플로우 2.4.1 기준으로 [https://developer.nvidia.com/cuda-10.1-download-archive-base?target_os=Windows&target_arch=x86_64&target_version=10&target_type=exelocal CUDA 10.1], [https://developer.nvidia.com/rdp/cudnn-archive cuDNN 7.6.4]를 설치해준다. CUDA는 그냥 설치하면 되고, cuDNN은 압축을 푼 후 내부의 파일들을 CUDA의 폴더에 복사해주면 된다. 기본경로는 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1 이다.
|
 
 
|}
 
|}
 
|-
 
|-
87번째 줄: 84번째 줄:
 
|
 
|
 
* CPU버전으로 실행(무시하고 진행하면 CPU버전으로 실행한다. 텐서플로우를 임포트 하기 전, 코드 상단에 os를 임포트하고 os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'를 넣어주면 에러메시지도 없앨 수 있다. 부작용으로... 에러메시지를 못본다.(기본적인 에러메시지는 뜬다.))
 
* CPU버전으로 실행(무시하고 진행하면 CPU버전으로 실행한다. 텐서플로우를 임포트 하기 전, 코드 상단에 os를 임포트하고 os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'를 넣어주면 에러메시지도 없앨 수 있다. 부작용으로... 에러메시지를 못본다.(기본적인 에러메시지는 뜬다.))
* GPU를 사용할 수 있는 환경 갖추기.(2.4.1 기준으로 [https://developer.nvidia.com/cuda-10.1-download-archive-base?target_os=Windows&target_arch=x86_64&target_version=10&target_type=exelocal CUDA 10.1], [https://developer.nvidia.com/rdp/cudnn-archive cuDNN 7.6.4]를 설치해준다.)
+
* GPU를 사용할 수 있는 환경 갖추기.(위 설치 참고.)
 
|-
 
|-
 
|AttributeError: module 'tensorflow' has no attribute 'Session'
 
|AttributeError: module 'tensorflow' has no attribute 'Session'

2021년 4월 23일 (금) 09:00 판

1 개요

머신러닝과 딥러닝에 많이 사용되어 머신러닝 라이브러리라 생각하는 사람들이 많은데, 실제로는 숫자계산을 위한 범용적인 라이브러리이다.

기본적으로 리눅스 환경에서 사용하기 위해 만들어진 라이브러리.

1.1 설치

설치가 까다로운 편이다. 요구하는 파이썬 버전 조건도 제한적이라 도커 안에서 다루는 편이 편할 것 같다.

OS 방법
Window
과정 설명
사전준비
  1. tensorflow가 요구하는 파이썬 버전 확인하고 다시 설치해준다.(https://www.tensorflow.org/install?hl=ko)
  2. pip install --upgrade pip
  3. pip install tensorflow를 할 때 ERROR: Could not find a version that satisfies the requirement tensorflow가 뜬다면 파이썬이 64bit용이 아니기 때문이다.(텐서플로우는 64bit 기반)
  4. cpu stable 버전이 요구하는 넘파이 버전이 일정 미만일 수 있다.
GPU사용준비 텐서플로우 2.4.1 기준으로 CUDA 10.1, cuDNN 7.6.4를 설치해준다. CUDA는 그냥 설치하면 되고, cuDNN은 압축을 푼 후 내부의 파일들을 CUDA의 폴더에 복사해주면 된다. 기본경로는 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1 이다.

1.2 설치확인

과정 설명 방법
설치확인 텐서플로우 버전에 따라 명령어가 다르다. 버전 확인 후 알맞은 방법으로 hello를 표시해보자.
과정 설명
1.x버전
import tensorflow as tf

sess = tf.Session()
hello = tf.constant('hello')
print(sess.run(hello))
2.x버전 Session을 정의하고 run의 과정이 빠졌다.
import tensorflow as tf

node1 = tf.constant(3.0, dtype=tf.float32)
node2 = tf.constant(4.0)

tf.print(node1,node2)
학습 등의 이유로 굳이 Session의 정의가 필요할 땐 다음과 같은 코드를 상단에 넣는다. 그러면 1.x버전과 같은 용법을 사용할 수 있다.
# import tensorflow as tf
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
버전확인
import tensorflow as tf

print(tf.__version__)

1.3 에러

에러 원인 해결방법
Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found 2.1버전 이후부터 패키지에 CPU, GPU버전이 모두 설치된다.
  • CPU버전으로 실행(무시하고 진행하면 CPU버전으로 실행한다. 텐서플로우를 임포트 하기 전, 코드 상단에 os를 임포트하고 os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'를 넣어주면 에러메시지도 없앨 수 있다. 부작용으로... 에러메시지를 못본다.(기본적인 에러메시지는 뜬다.))
  • GPU를 사용할 수 있는 환경 갖추기.(위 설치 참고.)
AttributeError: module 'tensorflow' has no attribute 'Session' 2.X버전은 session정의가 없어진다. 1.x버전의 문법으로 명령을 실행할 때 나오는 에러. 위의 설치 참고.