直接在脚本中配置 Theano [英] Theano config directly in script
问题描述
我是 Theano 的新手,我想知道如何直接从脚本配置默认设置(不设置环境变量).例如.这是一个有效的解决方案(source):
I'm new to Theano and I wonder how to configure the default setting directly from script (without setting envir. variables). E.g. this is a working solution (source):
$ THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python check1.py
我打算提出仅由以下人员执行的相同解决方案:
I intend to come up with the identical solution that is executed by only:
$ python check1.py
和附加参数直接在脚本本身中设置.例如.有点像这样:
and the additional parameters are set directly in the script itself. E.g. somehow like this:
import theano
theano.set('mode', 'FAST_RUN')
theano.set('device', 'gpu')
theano.set('floatX', 'float32')
# rest of the script
有可能吗?我阅读了 配置页面,它提供了允许我阅读已设置的信息值(但不是我自己设置).
Is it even possible? I read the config page which provides the information that allows me to read the already set values (but not to set them by myself).
推荐答案
当你这样做时:
$ THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python check1.py
您实际上所做的只是在运行 Python 脚本之前设置环境变量.
All you're actually doing is setting an environment variable before running the Python script.
您也可以在 Python 中设置环境变量.例如,THEANO_FLAGS
环境变量可以像这样在 Python 中设置:
You can set environment variables in Python too. For example, the THEANO_FLAGS
environment variable can be set inside Python like this:
import os
os.environ["THEANO_FLAGS"] = "mode=FAST_RUN,device=gpu,floatX=float32"
请注意,导入 Theano 后某些 Theano 配置变量无法更改,因此没问题:
Note that some Theano config variables cannot be changed after importing Theano so this is fine:
import os
os.environ["THEANO_FLAGS"] = "mode=FAST_RUN,device=gpu,floatX=float32"
import theano
但这不会按预期工作:
import theano
import os
os.environ["THEANO_FLAGS"] = "mode=FAST_RUN,device=gpu,floatX=float32"
这篇关于直接在脚本中配置 Theano的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!