Keras设定GPU使用内存大小方式(Tensorflow backend)
作者:mjiansun 时间:2021-12-20 22:15:12
通过设置Keras的Tensorflow后端的全局变量达到。
import os
import tensorflow as tf
import keras.backend.tensorflow_backend as KTF
def get_session(gpu_fraction=0.3):
'''Assume that you have 6GB of GPU memory and want to allocate ~2GB'''
num_threads = os.environ.get('OMP_NUM_THREADS')
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=gpu_fraction)
if num_threads:
return tf.Session(config=tf.ConfigProto(
gpu_options=gpu_options, intra_op_parallelism_threads=num_threads))
else:
return tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
使用过程中显示的设置session:
import keras.backend.tensorflow_backend as KTF
KTF.set_session(get_session())
补充知识:限制tensorflow的运行内存 (keras.backend.tensorflow)
我就废话不多说了,大家还是直接看代码吧!
import tensorflow as tf
from keras.backend.tensorflow_backend import set_session
config = tf.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.5 #half of the memory
set_session(tf.Session(config=config))
来源:https://blog.csdn.net/u013066730/article/details/77510033
标签:Keras,GPU,内存
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
wiondws XP下安装MySQL图文教程
2007-06-15 09:29:00
![](https://img.aspxhome.com/file/uploadpic/20076/15/2007615151328962.gif)
Python在字典中获取带权重的随机值实现方式
2022-12-11 05:21:44
使用DataFrame删除行和列的实例讲解
2021-03-05 21:06:04
python多线程socket编程之多客户端接入
2021-01-26 10:14:52
![](https://img.aspxhome.com/file/2023/4/69054_0s.png)
JQuery获取表单值
2009-11-19 13:17:00
用python生成mysql数据库结构文档
2021-05-15 12:04:33
![](https://img.aspxhome.com/file/2023/5/67945_0s.png)
vue学习笔记之动态组件和v-once指令简单示例
2024-01-01 07:50:52
![](https://img.aspxhome.com/file/2023/5/82745_0s.png)
python常用时间库time、datetime与时间格式之间的转换教程
2023-05-03 01:24:37
![](https://img.aspxhome.com/file/2023/8/98958_0s.png)
Python环境下安装PyGame和PyOpenGL的方法
2021-12-09 10:14:38
![](https://img.aspxhome.com/file/2023/3/81693_0s.png)
python 模拟网站登录——滑块验证码的识别
2023-04-17 16:16:29
![](https://img.aspxhome.com/file/2023/8/107798_0s.png)
Python使用百度翻译开发平台实现英文翻译为中文功能示例
2021-10-22 14:56:27
W3C网页内容无障碍指南2.0(WCAG)
2008-11-20 13:40:00
Python实现的FTP通信客户端与服务器端功能示例
2023-10-02 21:36:01
![](https://img.aspxhome.com/file/2023/9/63189_0s.png)
Django实现跨域的2种方法
2021-11-27 00:15:42
解决django服务器重启端口被占用的问题
2023-11-10 14:14:12
![](https://img.aspxhome.com/file/2023/1/105441_0s.jpg)
python 实现图片特效处理
2021-04-20 05:34:22
![](https://img.aspxhome.com/file/2023/5/81595_0s.png)
selenium使用chrome浏览器测试(附chromedriver与chrome的对应关系表)
2022-08-16 16:42:00
![](https://img.aspxhome.com/file/2023/0/98930_0s.png)
pandas dataframe drop函数介绍
2023-07-11 17:19:17
![](https://img.aspxhome.com/file/2023/8/101218_0s.png)
python3.5安装python3-tk详解
2021-01-02 02:15:23
![](https://img.aspxhome.com/file/2023/6/111996_0s.png)
python使用scapy模块实现ARP扫描的过程
2023-07-16 11:55:26
![](https://img.aspxhome.com/file/2023/0/85070_0s.png)