VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-save-the-network-in-xml-file-using-pybrain/

⇱ How To Save The Network In XML File Using PyBrain - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How To Save The Network In XML File Using PyBrain

Last Updated : 20 Feb, 2022

In this article, we are going to see how to save the network in an XML file using PyBrain in Python.

A network consists of several modules. These modules are generally connected with connections. PyBrain provides programmers with the support of neural networks. A network can be interpreted as an acyclic directed graph where each module serves the purpose of vertex/node and connections are assumed to edge.

Creating a Network

To create a network, PyBrain provides us with pybrain.tools.shortcuts. We can import buildNetwork shortcuts from this. The source code is given below,

Output:

FeedForwardNetwork-8

  Modules:

   [<BiasUnit 'bias'>, <LinearLayer 'in'>, <SigmoidLayer 'hidden0'>, <LinearLayer 'out'>]

  Connections:

   [<FullConnection 'FullConnection-4': 'hidden0' -> 'out'>, <FullConnection 'FullConnection-5': 'in' -> 'hidden0'>, <FullConnection 'FullConnection-6': 'bias' -> 'out'>, <FullConnection 'FullConnection-7': 'bias' -> 'hidden0'>]

Saving the created network in an XML file

we can use NetworkWriter library from pybrain.tools.customxml. It provides us writeToFile() function whose syntax is given below,

Syntax: NetworkWriter.writeToFile() 

Parameters:

  • writeToFile(network, xml_file)
  • network: The created network
  • xml_file: The name of the xml file with extension

This function will first create an XML file with the name passed as the parameter to the function and save the created myNetwork in it. 

Below is the complete implementation:

As you can see in the output, the myNetwork.XML file is generated by executing the below code. 

Output:

👁 Image

myNetwork.xml file:

👁 Image
Comment
Article Tags: