python - 如何实现tensorflow session 配置

标签 python memory tensorflow config

我想按照 this topic 中的说明设置 gpu 限制.

但我的代码是这样的:

deep_grap = tf.Graph()
with deep_grap.as_default():
    ### graph definition here
    ### graph definition here

with tf.Session(graph=deep_grap) as sess:
    tf.initialize_all_variables().run()
    ### more computations here

在这种情况下,如何在我的代码中设置配置?
我没有直接的 sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))线在这里。谢谢!

最佳答案

您可以通过 session 配置,一个 tf.ConfigPrototf.Session() with 中的初始化程序陈述:

deep_graph = tf.Graph()
with deep_graph.as_default():
    ### graph definition here
    ### graph definition here

config = tf.ConfigProto(gpu_options=...)

with tf.Session(graph=deep_graph, config=config) as sess:
    tf.initialize_all_variables().run()
    ### more computations here

关于python - 如何实现tensorflow session 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41028919/

相关文章:

Python 键入 : Mypy errors with overload "overlap" when signatures are different

linux - 锁频 Cortex A15 设备上内存带宽(但不是 CPU 性能)的奇怪小变化

python - 如何从 tensorflow 检查点文件正确恢复网络训练?

python - 如何从 Tensorflow 中的字符串张量中随机删除空格

python - pytorch 运行时错误 : Expected object of scalar type Double but got scalar type Float

python - 在 Swift 中运行 Python

Python 3.7 Scapy 安装失败

c - 为什么 C 中的 sizeof 运算符在 NOT 操作的情况下给出不同的输出?

performance - 在ActionScript 3中扩展类的负面影响是什么?

python - 如何在 Keras 中实现 Salt&Pepper 层?