tensorflow指定GPU与动态分配GPU memory设置
作者:sherry颖 时间:2023-01-16 11:30:24
在tensorflow中,默认指定占用所有的GPU,如需指定占用的GPU,可以在命令行中:
export CUDA_VISIBLE_DEVICES=1
这样便是只占用1号GPU,通过命令
nvidia-smi
可以查看各个GPU的使用情况。
另外,也可以在python程序中指定GPU,并且动态分配memory,代码如下
import os
import sys
os.environ['CUDA_VISIBLE_DEVICES'] = sys.argv[1]
import tensorflow as tf
from keras.backend.tensorflow_backend import set_session
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
set_session(tf.Session(config=config))
这样,占用的GPU就是sys.argv[1]了,并且会按需分配memory。
来源:https://blog.csdn.net/sherry_jy/article/details/79564930
标签:tensorflow,GPU,分配,memory
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python入门教程之运算符与控制流
2022-08-04 03:38:40
![](https://img.aspxhome.com/file/2023/8/89008_0s.png)
Python读取指定日期邮件的实例
2023-05-28 17:20:01
pyqt5与matplotlib的完美结合实例
2022-01-09 12:23:59
老生常谈Python进阶之装饰器
2022-05-20 10:51:23
python 的 scapy库,实现网卡收发包的例子
2021-08-08 17:25:05
Python多线程实现支付模拟请求过程解析
2023-04-09 17:59:35
python3+dlib实现人脸识别和情绪分析
2023-10-18 12:07:10
![](https://img.aspxhome.com/file/2023/2/76032_0s.png)
PyCharm利用pydevd-pycharm实现Python远程调试的详细过程
2022-01-22 19:54:26
![](https://img.aspxhome.com/file/2023/4/115844_0s.png)
Go操作redis与redigo的示例解析
2024-04-28 09:12:38
asp如何用SA-FileUp上传多个HTML文件?
2010-05-18 18:27:00
Go Redis客户端使用的两种对比
2024-05-09 09:31:15
![](https://img.aspxhome.com/file/2023/2/127432_0s.png)
BeautifulSoup获取指定class样式的div的实现
2023-05-10 20:39:14
python 实现敏感词过滤的方法
2022-08-09 10:22:51
Python中的Matplotlib模块入门教程
2023-08-14 23:05:16
![](https://img.aspxhome.com/file/2023/8/99168_0s.png)
Golang中的sync.WaitGroup用法实例
2023-08-31 03:57:28
Python 队列Queue和PriorityQueue解析
2023-07-15 20:31:11
![](https://img.aspxhome.com/file/2023/8/87938_0s.png)
matplotlib之pyplot模块坐标轴范围设置(autoscale(),xlim(),ylim())
2022-03-15 09:01:16
![](https://img.aspxhome.com/file/2023/6/89186_0s.png)
Python3.7基于hashlib和Crypto实现加签验签功能(实例代码)
2023-03-25 16:23:00
深度定制Python的Flask框架开发环境的一些技巧总结
2022-12-29 21:50:22
详解python websocket获取实时数据的几种常见链接方式
2023-09-20 08:22:23