keras with pytorch backend : GPU版

1. My OS is Ubuntu 20.04

2. Install cuda 12.2.0 (cuda_12.2.0_535.54.03_linux.run) as well as NIVDIA Driver 535

3. Install cudnn(cudnn-local-repo-ubuntu2004-8.9.7.29_1.0-1_amd64.deb)

4. download two requirement files form keras github homepage:

  • requirements-common.txt
  • requirements-torch-cuda.txt

5. create a conda env

conda create -y -n keras-pytorch python=3.103.10
conda activate keras-pytorchtorch
pip install -r requirements-torch-cuda.txt
pip install keras --upgrade

 6. test & usage:

import os
import torch
# To test running torch with GPU or not
torch.cuda.is_available()        # if GPU is sucessfully, it will return True
# select pytorch as keras backend
os.environ["KERAS_BACKEND"] = "torch"
import keras
# To check keras backend and keras version
keras.backend.backend()
keras.__version__

你可能感兴趣的:(keras,pytorch,人工智能)