Theano config directly in script

一笑奈何 提交于 2019-12-20 10:35:09

问题


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).


回答1:


When you do this:

$ THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python check1.py

All you're actually doing is setting an environment variable before running the Python script.

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"

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

But this will not work as expected:

import theano
import os
os.environ["THEANO_FLAGS"] = "mode=FAST_RUN,device=gpu,floatX=float32"


来源:https://stackoverflow.com/questions/33988334/theano-config-directly-in-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!