- import tensorflow as tf
- # 只利用 30% 的 GPU 記憶體
- gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.3)
- sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
- # 設定 Keras 利用的 TensorFlow Session
- tf.keras.backend.set_session(sess)
- # 利用 Keras 創設模型
- # ..
複製代碼 

解決方法
1. 指定 GPU 顯示卡
用GPU RUN PYTHON時,
泛起毛病訊息
- failed to create cublas handle: cublas_status_alloc_failed
複製代碼
3.主動增長 GPU 記憶體用量
網站架設
4. 如果還是不可
換CUDA跟CUDNN版本
文章出處: NetYea網頁設計
2. 指定 GPU 記憶體的佔用量
- import tensorflow as tf
- # 主動增進 GPU 記憶體用量
- gpu_options = tf.GPUOptions(allow_growth=True)
- sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
- # 設定 Keras 使用的 Session
- tf.keras.backend.set_session(sess)
- # 利用 Keras 建樹模子
- # ..
複製代碼
- import os
- # 利用第一張與第三張 GPU 卡
- os.environ["CUDA_VISIBLE_DEVICES"] = "0,2"
-
複製代碼