简体   繁体   English

如何限制TF Slim中的GPU内存使用?

[英]How to limit GPU memory use in TF Slim?

When training using TF Slim's train_image_classifier.py I would like to tell Slim to only allocate what GPU memory it needs, rather than allocating all the memory. 当使用TF Slim的train_image_classifier.py进行训练时,我想告诉Slim仅分配所需的GPU内存,而不分配所有内存。

Were I using straight up TF and not Slim I could say this: 如果我使用TF而不是Slim,我可以这样说:

config = tf.ConfigProto()
config.gpu_options.allow_growth=True
sess = tf.Session(config=config)

Or even just this to put a hard cap on GPU memory use: 甚至仅仅是为了对GPU内存的使用设置硬性限制:

gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.333)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))

How can I tell Slim the same thing(s)? 我该如何告诉Slim同样的事情?

My comprehension fail is that Slim seems to use it's own loop and I can't find docs on the nitty gritty of configuring the loop. 我的理解失败是Slim似乎使用了它自己的循环,而我在配置循环的细节上找不到文档。 So, even if someone could point me to good Slim docs that'd be fantastic. 因此,即使有人可以将我指向优秀的Slim文档,也将是很棒的。

Thanks in advance! 提前致谢!

You can pass the allow_growth option via the session_config parameter that is passed to the train method as follow: 您可以通过session_config参数传递allow_growth选项,该参数传递给train方法,如下所示:

session_config = tf.ConfigProto()
session_config.gpu_options.allow_growth = True
slim.learning.train(..., session_config=session_config)

See tensorflow/contrib/slim/python/slim/learning.py#L615 and tensorflow #5530 . 参见tensorflow / contrib / slim / python / slim / learning.py#L615tensorflow#5530

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM