Using FANN and its Python bindings to construct neural networks
来源:互联网 发布:吊杆控制台编程 编辑:程序博客网 时间:2024/05/22 14:01
FANN stands for Fast Artificial Neural Network, which is a neural network library, originally intended only for C. However, due to the boost of the terrific script language – Python, the demand to use a FANN Python binding arises, which makes a perfect combination of the speed of C and elegance of Python.
The FANN Python Binding — pyfann, seems a bit out of date. The conventional way “python setup.py install” cannot do the right thing with VS 2010 or later. So after experienced a lot of difficulties during the configuration of pyfann, I decided to record all these procedures down to help other guys who also suffers from this pain..
Below is my method to build pyfann on Windows 7, which is independent of “setup.py”.
=============================================
Step 1 – Download FANN 2.1.0, swig 2.0.8, Python 3.2, VS 2010
=============================================
Well, you know how to do it.
============================
Step 2 – Adapting FANN for Python 3.x
============================
Up to today (Jun 23, 2013), FANN is still not compatible with Python 3.x. However, this issue can be settled by the lovely tool 2to3.py. So you should type the following command in the cmd window and enter (you know what ‘<>’ means).
cd <Python-installation-path>/Tools/Scripts
python 2to3.py -wWno <FANN-installation-path>/python3 <FANN-installation-path>/pythonAnd also remember to copy the non-python files to the newly created python3 folder.
============================
Step 3 – Parse the Swig interface file “pyfann.i”
============================
This is done by
cd <FANN-installation-path>/python3/pyfann
swig -c++ -python pyfann.i
This will generate a file named “pyfann_wrap.cxx”.
============================
Step 4 – Build _libfann.pyd in VS 2010
============================
This is done by
(1) Create a new project, use the AppWizard to select an empty DLL project.
(2) Add pyfann_wrap.cxx, doublefann.c to the source folder of the project, add doublefann.h to the header folder of the project.
(3) Switch to RELEASE configuration.
(4) Select the settings for the entire project and go to “C++:Preprocessor”. Add the Python include directories under “Additional include directories”.
(5) Define the symbol __WIN32__ and FANN_DLL_EXPORTS under preprocessor options.
(6) Finally, select the settings for the entire project and go to “Link Options”. Add Python library file to your link libraries. For example “python32.lib”. Also, set the name of the output file to match the name of your Python module, ie. _libfann.pyd.
(7) Build your project.
===========================================
Step 5 – Have a try wth the generated FANN Python binding
===========================================
Modify the “simple_train.py” under <FANN-installation-path>/python3/examples. And then run.
import osimport syssys.path.insert(0, os.path.normpath(os.path.join(sys.path[0], '../pyfann')))import libfann as pyfannconnection_rate = 1learning_rate = 0.7num_input = 2num_neurons_hidden = 4num_output = 1desired_error = 0.0001max_iterations = 100000iterations_between_reports = 1000ann = pyfann.neural_net()ann.create_sparse_array(connection_rate, (num_input, num_neurons_hidden, num_output))ann.set_learning_rate(learning_rate)ann.set_activation_function_output(pyfann.SIGMOID_SYMMETRIC_STEPWISE)ann.train_on_file("../../examples/xor.data", max_iterations, iterations_between_reports, desired_error)
Enjoy!
- Using FANN and its Python bindings to construct neural networks
- Ranking with Recursive Neural Networks and Its Application to Multi-document Summarization
- 论文阅读:How to Construct Deep Recurrent Neural Networks
- Matlab to C++ using boost.ublas and boost.bindings
- A Fast and Accurate Dependency Parser using Neural Networks
- LENSES CLASSIFICATION USING NEURAL NETWORKS
- 【Notes on Neural Networks and Deep Learning】(to be continued)
- [神经网络]1.3-Using neural nets to recognize handwritten digits-The architecture of neural networks(翻译)
- Python: Neural Networks
- Neural Networks and Deep Learning
- Neural Networks and Backpropagation Algorithm
- Neural Networks and Deep Learning
- Neural Networks, Manifolds, and Topology
- Neural networks and Deep Learning
- Neural Networks and Deep Learning
- Introduction to debugging neural networks
- Introduction to debugging neural networks
- Learning and Transferring Mid-Level Image Representations using Convolutional Neural Networks
- 分享30个独特的 404 错误页面设计模板
- C#关键字var的简要说明
- oracle数据库的5种约束类型
- POJ 2914 Minimum Cut 最小割集Stoer-Wagner算法(全局最小割)
- 《jQuery权威指南》学习笔记之第2章 jQuery选择器
- Using FANN and its Python bindings to construct neural networks
- 北邮校长方滨兴将离职 临别奉送学生“六好”锦囊
- 产品经理常犯的七大错误
- setup virtual box extention for lubuntu
- 2013春季学期总结
- 解决cisvc.exe占用CPU
- 创建关闭进程
- HTTP基础培训及一点点感悟 - 含PPT下载
- 整数取其相反数实现