【Theano】安装教程

1.操作系统

Linux下安装会比windows下省事很多。

2.安装anaconda

已内置python,numpy和scipy两个必要库以及一些其他库,自带安装。地址:continuum.io/downloads

Anaconda的一些命令(在Anaconda的命令行窗口输入):

conda list #该命令,将列出Anaconda安装的所有应用包,我们可以看到Anaconda已经安装了numpy, nose, pip, python, scipy, mingw等等。

conda install <pkg name> #该命令用于安装应用包,如 conda install numpy.

pip install <pkg name> #该命令用于安装应用包,如 pip install theano.

conda update <pkg name> #升级应用包,如 conda update python

3.安装mingw

conda install mingw libpython

跳过这一步的话,在import theano时出现:g++ not detected!

4.环境配置

在用户变量中,PATH添加C:\Anaconda;C:\Anaconda\Scripts;

并新建 PYTHONPATH:C:\Anaconda\Lib\site-packages\theano;

在cmd的home目录中新建 .theanorc.txt 文件(注意名字中的“.”),根据自己安装MinGW的路径写上MinGW的路径,我的如下:

[blas]
ldflags=


[gcc]
cxxflags = -IC:\Anaconda\MinGW

重启电脑

5.安装theano

别用什么theano.zip解压到目录底下或者theano_installer_latest.msi,不嫌麻烦你就去试,正确方式:cmd输入:pip install theano

(pip用法看这里:pip 安装使用详解

装完之后在ipython中输入以下两行代码测试一下:

import theano

theano.test()

没有error的话,恭喜你,安装成功了。

6.GPU加速

看这里:http://blog.csdn.net/mysql403/article/details/50902959

GPU加速首先就是安装CUDA,然而CUDA只支持NVIDIA显卡,因为CUDA软件就是他家出的,如果你的本并不是NVIDIA显卡,别费劲了

7.BLAS

看看numpy是不是已经默认BLAS加速了,在python里输入:

import numpy

id(numpy.dot) == id(numpy.core.multiarray.dot)

结果为False表示已经成功依赖了BLAS加速,如果是Ture则表示用的是python自己的实现,并没有加速。

参考:https://www.zhihu.com/question/35485591/answer/74363495

发布了392 篇原创文章 · 获赞 486 · 访问量 239万+
展开阅读全文

theano 报错 module 'configparser' has no attribute 'ConfigParser' 用的是Anaconda3 python3.6

09-30

>theano 报错 module 'configparser' has no attribute 'ConfigParser' 用的是Win10 Anaconda3 python3.6 ``` from sklearn.datasets import load_boston import theano.tensor as T import numpy as np import matplotlib.pyplot as plt import theano class Layer(object): def __init__(self,inputs,in_size,out_size,activation_function=None): self.W = theano.shared(np.random.normal(0,1,(in_size,out_size))) self.b = theano.shared(np.zeros((out_size,)) + 0.1) self.Wx_plus_b = T.dot(inputs, self.W) + self.b self.activation_function = activation_function if activation_function is None: self.outputs = self.Wx_plus_b else: self.outputs = self.activation_function(self.Wx_plus_b) def minmax_normalization(data): xs_max = np.max(data, axis=0) xs_min = np.min(data, axis=0) xs = (1-0)*(data - xs_min)/(xs_max - xs_min) + 0 return xs np.random.seed(100) x_dataset = load_boston() x_data = x_dataset.data # minmax normalization, rescale the inputs x_data = minmax_normalization(x_data) y_data = x_dataset.target[:,np.newaxis] #cross validation, train test data split x_train, y_train = x_data[:400], y_data[:400] x_test, y_test = x_data[400:], y_data[400:] x = T.dmatrix('x') y = T.dmatrix('y') l1 = Layer(x, 13, 50, T.tanh) l2 = Layer(l1.outputs, 50, 1, None) #compute cost cost = T.mean(T.square(l2.outputs - y)) #cost = T.mean(T.square(l2.outputs - y)) + 0.1*((l1.W**2).sum() + (l2.W**2).sum()) #l2 regulization #cost = T.mean(T.square(l2.outputs - y)) + 0.1*(abs(l1.W).sum() + abs(l2.W).sum()) #l1 regulization gW1, gb1, gW2, gb2 = T.grad(cost, [l1.W,l1.b,l2.W,l2.b]) #gradient descend learning_rate = 0.01 train = theano.function(inputs=[x,y], updates=[(l1.W,l1.W-learning_rate*gW1), (l1.b,l1.b-learning_rate*gb1), (l2.W,l2.W-learning_rate*gW2), (l2.b,l2.b-learning_rate*gb2)]) compute_cost = theano.function(inputs=[x,y], outputs=cost) #record cost train_err_list = [] test_err_list = [] learning_time = [] for i in range(1000): if 1%10 == 0: #record cost train_err_list.append(compute_cost(x_train,y_train)) test_err_list.append(compute_cost(x_test,y_test)) learning_time.append(i) #plot cost history plt.plot(learning_time, train_err_list, 'r-') plt.plot(learning_time, test_err_list,'b--') plt.show() #作者 morvan莫凡 https://morvanzhou.github.io ``` 报错了: Traceback (most recent call last): File "C:/Users/Elena/PycharmProjects/theano/regularization.py", line 1, in <module> from sklearn.datasets import load_boston File "C:\Users\Elena\Anaconda3\lib\site-packages\sklearn\datasets\__init__.py", line 22, in <module> from .twenty_newsgroups import fetch_20newsgroups File "C:\Users\Elena\Anaconda3\lib\site-packages\sklearn\datasets\twenty_newsgroups.py", line 44, in <module> from ..feature_extraction.text import CountVectorizer File "C:\Users\Elena\Anaconda3\lib\site-packages\sklearn\feature_extraction\__init__.py", line 10, in <module> from . import text File "C:\Users\Elena\Anaconda3\lib\site-packages\sklearn\feature_extraction\text.py", line 28, in <module> from ..preprocessing import normalize File "C:\Users\Elena\Anaconda3\lib\site-packages\sklearn\preprocessing\__init__.py", line 6, in <module> from ._function_transformer import FunctionTransformer File "C:\Users\Elena\Anaconda3\lib\site-packages\sklearn\preprocessing\_function_transformer.py", line 5, in <module> from ..utils.testing import assert_allclose_dense_sparse File "C:\Users\Elena\Anaconda3\lib\site-packages\sklearn\utils\testing.py", line 61, in <module> from nose.tools import raises as _nose_raises File "C:\Users\Elena\Anaconda3\lib\site-packages\nose\__init__.py", line 1, in <module> from nose.core import collector, main, run, run_exit, runmodule File "C:\Users\Elena\Anaconda3\lib\site-packages\nose\core.py", line 11, in <module> from nose.config import Config, all_config_files File "C:\Users\Elena\Anaconda3\lib\site-packages\nose\config.py", line 6, in <module> import configparser File "C:\Users\Elena\Anaconda3\Lib\site-packages\theano\configparser.py", line 15, in <module> import theano File "C:\Users\Elena\Anaconda3\lib\site-packages\theano\__init__.py", line 88, in <module> from theano.configdefaults import config File "C:\Users\Elena\Anaconda3\lib\site-packages\theano\configdefaults.py", line 17, in <module> from theano.configparser import (AddConfigVar, BoolParam, ConfigParam, EnumStr, File "C:\Users\Elena\Anaconda3\lib\site-packages\theano\configparser.py", line 77, in <module> theano_cfg = (configparser.ConfigParser if PY3 **AttributeError: module 'configparser' has no attribute 'ConfigParser**' 把theano里的configparser.py文件里的ConfigParser改成了configparser还是不行 换了模块import configparsor也不行。。。![图片说明](https://img-ask.csdn.net/upload/201909/30/1569832318_223436.png) 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览