安装mingw+Theano+keras
一、关于深度学习框架TensorFlow、Theano 和 Keras
https://www.cnblogs.com/shenxiaolin/p/11121152.html
Keras 可以基于两个Backend(也就是Keras 基于什么东西来做运算):
一个是 Theano,一个是 Tensorflow(默认)。可以通过修改Backend将默认的Tensorflow改为Theano。
如果我们选择Theano作为Keras的Backend, 那么Keras就用 Theano 在底层搭建你需要的神经网络;
同样,如果选择 Tensorflow 的话呢,Keras 就使用 Tensorflow 在底层搭建神经网络。
二、可以安装theano、keras的python版本
theano、keras兼容的python版本:
- theano -> python[version='>=2.7,<2.8.0a0|>=3.7,<3.8.0a0|>=3.8,<3.9.0a0|>=3.6,<3.7.0a0|>=3.5,<3.6.0a0']
- keras -> python[version='>=3.5,<3.6.0a0|>=3.6,<3.7.0a0']
我们选择python3.5进行安装。
三、安装mingw+Theano+keras
1. 进入cmd,创建虚拟环境keras:
至于需要创建虚拟环境的原因,请参见文章:Anaconda、Jupyterlab、虚拟环境、Kernel
conda create --name keras python=3.5
2. 进入虚拟环境keras:
conda activate keras
3.安装 mingw 和 libpython :
conda install mingw libpython
报错:
PackagesNotFoundError: The following packages are not available from current channels:
- mingw
Current channels:
- https://repo.anaconda.com/pkgs/msys2/win-64
- https://repo.anaconda.com/pkgs/msys2/noarch
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/win-64
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/noarch
- https://repo.anaconda.com/pkgs/main/win-64
- https://repo.anaconda.com/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/r/win-64
- https://repo.anaconda.com/pkgs/r/noarch
To search for alternate channels that may provide the conda package you are looking for, navigate to
https://anaconda.org
and use the search bar at the top of the page.
解决:
anaconda search -t conda mingw
显示:
Using Anaconda API: https://api.anaconda.org
C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py:857: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning)
Packages:
Name | Version | Package Types | Platforms | Builds
------------------------- | ------ | --------------- | --------------- | ----------
RMG/mingwpy | 0.1.0 | conda | win-32, win-64 | py27_3
: GCC for Windows 64 & 32 bits
bcilab/qt_mingw_32_release | 5.15.0 | conda | win-32 | 0
bcilab/qt_mingw_64_release | 5.15.0 | conda | win-64 | 0
bcilab/resonance_beta_mingw_32 | 3.3.1 | conda | win-32 | 103
bcilab/resonance_mingw_32 | 3.4.1 | conda | win-32 | 11, 13, 138, 20, 0, 79, 18, 27, 23, 28, 132, 131, 89, 72, 134, 80, 78, 86, 87, 84, 85
bcilab/resonance_mingw_64 | 3.4.1 | conda | win-32, win-64 | 25, 27, 20, 18, 28, 0, 2, 4
conda-forge/mingwpy | 0.1.0 | conda | win-32, win-64 | py27_2, py34_1, py34_0, py27_0, py27_1, py35_0, py34_2
: GCC for Windows 64 & 32 bits
free/mingw | 4.7 | conda | win-32, win-64 | 1, 0
ijstokes/mingwpy | v0.1.0 | conda | win-64 | 0.1.0
lucaszw/mingw-runtime | 4.7 | conda | win-32 | 0
mfix/libboost-mingw | 1.67.0 | conda | win-64 | 1
mwm126/libboost-mingw | 1.65.1 | conda | win-64 | 1, 0
mwojcikowski/mingwpy | 0.1.0 | conda | win-32, win-64 | py34_2, py34_1, py34_0, py27_0, py27_1, py35_0, py27_2
: GCC for Windows 64 & 32 bits
omnia/mingwpy | 0.1.0 | conda | win-32, win-64 | py27_3, py36_3, py34_3, py33_3
: GCC for Windows 64 & 32 bits
takluyver/mingw-w64 | 3.1.0.1 | conda | linux-64 | 0
tz-lom/qt_mingw_64_release | | conda | win-64 | 0
tz-lom/resonance_mingw_32 | | conda | win-32 | 139
tz-lom/resonance_mingw_64 | | conda | win-64 | 27
ukoethe/mingw | | conda | win-64 | 0, vc11
ukoethe/mingw-for-msvc | 4.7.2 | conda | win-64 | 0
: Configure MinGW as a subtool of Visual Studio (needed to compile packages that MSVC can't handle, e.g. Fortran sources)
ukoethe/mingw-for-msvc-build | 4.7.2 | conda | win-64 | 0
: Configure MinGW as a subtool of Visual Studio (needed to compile packages that MSVC can't handle, e.g. Fortran sources)
wheeler-microfluidics/mingw-runtime | 4.7 | conda | win-32 | 0
wheeler-microfluidics/tdm-mingw | 1.908.0 | conda | win-32 | 1
willyd/openblas-mingw | 0.2.14 | conda | win-64 | 0
Found 24 packages
Run 'anaconda show <USER/PACKAGE>' to get installation details
选择一个从上述路径中选一个可行的路径再次安装:例如选择 free/mingw | 4.7 | conda | win-32, win-64 | 1, 0
conda install -c https://conda.anaconda.org/free mingw
安装libpython:
conda install libpython
查看是否成功:
g++ --version
g++.exe (GCC) 4.7.0 20111220 (experimental)
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
4. 安装theano:
conda install theano
有可能会出现连接失败的问题,重试即可。
5. 安装keras:
conda install keras
6. 检验是否安装成功:
1. 进入python,使用import theano
检验theano是否安装成功:
(keras) C:\Users\huipu>python
Python 3.8.11 (default, Aug 6 2021, 09:57:55) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import theano
WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions.
出现了警告:Using NumPy C-API based implementation for BLAS functions.
警告解决方法:
a. 第一步:安装三个包
#在环境中安装这三个包
conda install mkl
conda install mkl-service
conda install blas
b. 第二步:在用户目录下放置一个文件
在桌面新建一个txt文档,输入如下内容:
#我建的是这个
[blas]
ldflags=-lmkl_rt
或者输入如下内容:
[blas]
ldflags=-lblas
将文档另存为文件名:.theanorc.txt ,文档类型为:所有文件(.) 。文件的存放路径为:C:\Users\你的电脑用户名 。
c. 验证,再次import theano
就没有警告啦!
(keras) C:\Users\huipu>python
Python 3.8.11 (default, Aug 6 2021, 09:57:55) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import theano
>>> print (theano.config.blas.ldflags)
-lmkl_rt
2. theano.test()检验theano是否真的安装成功:
虽然现在import成功了。但是,大佬都用theano.test()来检验theano是否真的安装成功,即使出现了一堆错误,但是如果出现default=0 的话,就说明安装成功了~ ~
去python里theano.test():
(keras)C:\Users\huipu>python
Python 3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 16:05:27) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import theano
>>> theano.test()
Theano version 1.0.2
theano is installed in C:\ProgramData\Anaconda3\envs\theano_2\lib\site-packages\theano
NumPy version 1.14.2
NumPy relaxed strides checking option: True
NumPy is installed in C:\ProgramData\Anaconda3\envs\theano_2\lib\site-packages\numpy
Python version 3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 16:05:27) [MSC v.1900 64 bit (AMD64)]
nose version 1.3.7
EE...........E.EE.....EEEE....E..................................C:\ProgramData\Anaconda3\envs\theano_2\lib\site-packages\theano\gof\vm.py:887: UserWarning: CVM does not support memory profile, using Stack VM.
'CVM does not support memory profile, using Stack VM.')
.E.........SS.............0.7415943278643314
0.7415943278643314
0.7415943278643314
0.7415943278643314
....E...E.....EEEEE..E......................................E...................................................E......................EC:\ProgramData\Anaconda3\envs\theano_2\lib\site-packages\theano\gof\vm.py:890: UserWarning: LoopGC does not support partial evaluation, using Stack VM.
'LoopGC does not support partial evaluation, '
.C:\ProgramData\Anaconda3\envs\theano_2\lib\site-packages\theano\gof\vm.py:890: UserWarning: LoopGC does not support partial evaluation, using Stack VM.
'LoopGC does not support partial evaluation, '
C:\ProgramData\Anaconda3\envs\theano_2\lib\site-packages\theano\gof\vm.py:890: UserWarning: LoopGC does not support partial evaluation, using Stack VM.
'LoopGC does not support partial evaluation, '
.....EEEESEEEEEEEESEEEES.C:\ProgramData\Anaconda3\envs\theano_2\lib\site-packages\theano\gpuarray\type.py:895: UserWarning: config.experimental.unpickle_gpu_on_cpu is set to True. Unpickling GpuArray as numpy.ndarray
"config.experimental.unpickle_gpu_on_cpu is set to True. "
.EEEEEES.....SEE...C:\ProgramData\Anaconda3\envs\theano_2\lib\site-packages\theano\sandbox\rng_mrg.py:1031: UserWarning: MRG_RandomStreams.multinomial_wo_replacement() is deprecated and will be removed in the next release of Theano. Please use MRG_RandomStreams.choice() instead.
warnings.warn('MRG_RandomStreams.multinomial_wo_replacement() is '
.C:\ProgramData\Anaconda3\envs\theano_2\lib\site-packages\theano\sandbox\rng_mrg.py:1031: UserWarning: MRG_RandomStreams.multinomial_wo_replacement() is deprecated and will be removed in the next release of Theano. Please use MRG_RandomStreams.choice() instead.
warnings.warn('MRG_RandomStreams.multinomial_wo_replacement() is '
...EES..E....E.......EEEE.EEEEEEEEEEEEEEEEEEEE.....EEEEE...E....E..E..S.....EEEEEEEEE......EEE......EEEE..........SEE..SSSS.......S.....E...
======================================================================
ERROR: Failure: ImportError (No module named 'parameterized')
======================================================================
ERROR: test_nnet (theano.compile.tests.test_misc.TestNnet)
======================================================================
ERROR: theano.compile.tests.test_mode.test_no_output_from_implace
======================================================================
ERROR: theano.compile.tests.test_monitormode.test_not_inplace
======================================================================
ERROR: theano.compile.tests.test_nanguardmode.test_NanGuardMode
======================================================================
ERROR: test_input_aliasing_affecting_inplace_operations (theano.compile.tests.test_pfunc.Test_aliasing_rules)
======================================================================
ERROR: test_partial_input_aliasing_affecting_inplace_operations (theano.compile.tests.test_pfunc.Test_aliasing_rules)
======================================================================
ERROR: test_profiling (theano.compile.tests.test_profiling.Test_profiling)
======================================================================
ERROR: test_constant (theano.gof.tests.test_compute_test_value.TestComputeTestValue)
======================================================================
ERROR: test_ndarray (theano.gof.tests.test_compute_test_value.TestComputeTestValue)
======================================================================
ERROR: test_scan_err2 (theano.gof.tests.test_compute_test_value.TestComputeTestValue)
======================================================================
ERROR: test_shared (theano.gof.tests.test_compute_test_value.TestComputeTestValue)
======================================================================
ERROR: test_string_var (theano.gof.tests.test_compute_test_value.TestComputeTestValue)
======================================================================
ERROR: test_variable_only (theano.gof.tests.test_compute_test_value.TestComputeTestValue)
======================================================================
ERROR: test_node_outputs_not_used (theano.gof.tests.test_fg.TFunctionGraph)
======================================================================
ERROR: theano.gof.tests.test_link.test_sort_schedule_fn
======================================================================
ERROR: theano.gof.tests.test_vm.test_partial_function
======================================================================
ERROR: Demonstrate stochastic gradient descent optimization for a multilayer
======================================================================
ERROR: theano.tensor.tests.test_misc.test_bug_2009_07_17_borrowed_output
----------------------------------------------------------------------
Ran 413 tests in 32.590s
FAILED (SKIP=15, errors=101)
<nose.result.TextTestResult run=413 errors=101 failures=0>
我的确出现了这么一大堆错误,但是我也没看到default=0字样。
未完待续。。。
3.如果用高于3.5.X的python环境进行安装, theano.test()时会出现以下错误,并附带解决办法:
这是之前在Python 3.8环境中进行安装时发生的错误:
(theano) C:\Users\huipu>python
Python 3.8.11 (default, Aug 6 2021, 09:57:55) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import theano
>>> theano.test()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\ProgramData\Anaconda3\envs\theano\lib\site-packages\theano\__init__.py", line 148, in test
raise ImportError("The nose module is not installed."
ImportError: The nose module is not installed. It is needed for Theano tests.
test()出错了:提示nose模块没有安装。
错误解决方法:
不慌,首先我们来看看我们安装nose了没:
用pip list
和conda list
查看了一下,列表里都显示已安装nose 1.3.7
。而且在python里单独import nose
没出错:
(theano) C:\Users\huipu>python
Python 3.8.11 (default, Aug 6 2021, 09:57:55) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import nose
>>> nose
<module 'nose' from 'C:\\ProgramData\\Anaconda3\\envs\\theano\\lib\\site-packages\\nose\\__init__.py'>
>>> result=nose.run()
----------------------------------------------------------------------
Ran 0 tests in 0.069s
OK
所以我不由得怀疑:可能nose 1.3.7和当前的python环境3.8.11不兼容???
- 所以我先尝试升级nose包:
conda update nose
,升级完之后仍然是1.3.7版本。升级nose行不通。 - 既然nose升不了,那就降级python吧:Currently, Theano Release 1.0 only supports >=3.4 and < 3.6. If your Python version is higher than 3.5.X, try downgrading and then re-run the Theano test. Do let everyone know if that works.
重新安装一个3.5.X版本的python,就是重复之前的步骤就好。 - 再去test(),发现错误:没有nose模块。解决:安装nose模块。
(keras) C:\Users\huipu>python
Python 3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 16:05:27) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import theano
>>> theano.test()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\ProgramData\Anaconda3\envs\theano_2\lib\site-packages\theano\tests\main.py", line 107, in test
from nose.config import Config
ImportError: No module named 'nose'
#安装nose模块
conda install nose
装好之后,再去test(),会发现之前的ImportError: The nose module is not installed. It is needed for Theano tests.这个错误消失了!!!
说明降级python是有效的。不能用太高版本的python安装theano。
参考链接
WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions.
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/119069.html