theano学习笔记

本文介绍了Theano的环境搭建,包括使用pip安装0.9.0版本。详细讲解了Theano的基本用法,如创建tensor3类型的变量,以及如何设定共享变量的值。此外,还展示了如何保存和加载模型,通过pickle文件进行序列化和反序列化,确保模型权重的持久化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

theano

 一、搭建环境   

    安装:pip install theano==0.9.0

    卸载:pip uninstall theano
    查看版本号:import theano
                theano.__version__
    设置gpu\cpu:
        方法1:vim /root/.theanorc
                [global]
                model=FAST_RUN    (该模式运行速度快)
                device=cuda1 (或者gpu或cpu)
                floatX=float32
                [blas]
                ldflags=-L/usr/lib/libblas.so

        方法2:
            THEANO_FLAGS=mode=FAST_RUN,device=cuda,floatX=float32 python test_new.py
        备注:theano0.9以上版本,使用gpu新后端,device=gpu或cpu或cuda(新后端)
            #test_theano_gpu.py测试gpu/cpu,https://www.cnblogs.com/shouhuxianjian/p/4590224.html
            THEANO_FLAGS=mode=FAST_RUN,device=cuda,floatX=float32 python test_theano_gpu.py        
                <GpuArrayType<None>(float32, (False,))>    使用cpu
            THEANO_FLAGS=mode=FAST_RUN,device=cpu,floatX=float32 python test_theano_gpu.py
                <TensorType(float32, vector)>    使用cpu
            THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python test_theano_gpu.py
                <CudaNdarrayType(float32, vector)>    使用gpu
                
    tensorflow和theano同时要使用GPU,如何设置?
        如果.theanorc中device设置为gpu,那么tensorflow将无法使用GPU;
        如果.theanorc中device设置为cuda,那么theano在第二次调用中将无法使用GPU;
        因此,如果tensorflow和theano同时要使用GPU,.theanorc中device必须设置为cuda,而且指明哪一个cuda。如上面的device=cuda1。
        与此同时,tensorflow不需要特别指定GPU。

    pygpu安装:
        git clone https://github.com/Theano/libgpuarray.git
        cd libgpuarray
        mkdir Build
        cd Build
        cmake .. -DCMAKE_BUILD_TYPE=Release
        make
        make install
        cd ..
        python setup.py build
        python setup.py install    
        sudo ldconfig
        备注有测试过pygpu==0.6.5与theano==0.9.0 或者pygpu==0.7.5与theano==1.0.0 OK.
            pygpu版本如果为0.65,那么theano必须为0.9。如果为1.0,不兼容。无法成功import theano。
            pygpu版本如果为0.75,那么theano必须为1.0。如果为0.9,不兼容。无法正常初始化pygpu。
    
    例子:DeepAlgnmentNetwork: theano==0.9.0
        error:immporting theano: AttributeError: 'module' object has no attribute 'find_graphviz'
        解决方案:sudo pip uninstall -y pydot 或者 pip install pydot-ng        
        安装lasagne:https://github.com/Lasagne/Lasagne  (深度框架)
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值