Theano config directly in script

后端 未结 1 512
轮回少年
轮回少年 2021-02-04 08:54

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



        
相关标签:
1条回答
  • 2021-02-04 09:34

    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"
    
    0 讨论(0)
提交回复
热议问题