본문 바로가기
Python Library

[Windows] NVIDIA GPU 사용을 위한 WSL2에 Tensorflow 및 Keras 설치

by goatlab 2024. 2. 15.
728x90
반응형
SMALL

NVIDIA Driver

 

 

NVIDIA에서 제품에 맞는 드라이버를 설치한다.

 

WSL2 설치

 

 

PowerShell에서 WLS2를 설치한다.

 

wls --install

 

PowerShell에서 nvidia-smi 명령으로 GPU 서버를 확인한다.

 

nvidia-smi

 

Miniconda 설치

 

Miniconda Windows 프로그램을 설치한다.

 

콘다 환경 만들기

 

다음 명령을 사용하여 tf 라는 새 conda 환경을 만든다.

 

conda create --name tf python=3.9

 

가상 환경 활성화에서 에러가 발생한다면 PowerShell 실행 정책을 변경해야 한다.

 

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If using 'conda activate' from a batch script, change your
invocation to 'CALL conda.bat activate'.

To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - cmd.exe
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

 

PowerShell에서 다음 명령을 사용한다.

 

PS C:\Users> Get-ExecutionPolicy -Scope CurrentUser
Undefined
PS C:\Users> Get-ExecutionPolicy
Restricted
PS C:\Users> Get-ExecutionPolicy -List

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine       Undefined

 

다음 명령을 통해 인증서를 신뢰할 수 있는 인증 기관으로 가져와서 AllSigned 또는 RemoteSigned 실행 정책으로 서명된 스크립트를 실행할 수 있다.

 

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

 

그 다음, 생성한 가상 환경을 활성화한다.

 

conda activate tf

 

CUDA 설치

 

conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0

 

 

TensorFlow 설치

 

TensorFlow는 PyPI에만 공식적으로 출시되므로 pip 업그레이드를 권장한다.

 

pip install --upgrade pip
# Anything above 2.10 is not supported on the GPU on Windows Native
pip install "tensorflow<2.11"

 

설치 확인

 

PowerShell에서 CPU 설정을 확인한다.

 

python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

 

텐서가 반환되면 TensorFlow가 성공적으로 설치된 것이다. 그 다음으로, GPU 설정을 확인한다.

 

python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
python -c "from tensorflow.python.client import device_lib; print(device_lib.list_local_devices())"

 

GPU 장치 목록이 반환되면 TensorFlow가 성공적으로 설치된 것이다.

 

https://www.tensorflow.org/install/pip?hl=ko

 

pip로 TensorFlow 설치

이 페이지는 Cloud Translation API를 통해 번역되었습니다. pip로 TensorFlow 설치 컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요. 이 가이드는 TensorFlow의 최신 안정

www.tensorflow.org

728x90
반응형
LIST