neupy.storage module

neupy.storage.save(network, filepath)[source]

Save network parameters in HDF5 format.

Parameters:
network : network, list of layer or network
filepath : str

Path to the HDF5 file that stores network parameters.

Examples

>>> from neupy import layers, storage
>>>
>>> network = layers.Input(10) > layers.Softmax(3)
>>> storage.save_hdf5(network, '/path/to/parameters.hdf5')
neupy.storage.load(network, filepath, ignore_missing=False, load_by='names_or_order', skip_validation=True)[source]

Load network parameters from HDF5 file.

Parameters:
network : network, list of layer or network
filepath : str

Path to HDF5 file that will store network parameters.

ignore_missing : bool

False means that error will be triggered in case if some of the layers doesn’t have storage parameters in the specified source. Defaults to False.

load_by : {names, order, names_or_order}

Defines strategy that will be used during parameter loading

  • names - Matches layers using their names.
  • order - Matches layers using their relative position.
  • names_or_order - First, method tries to match layers using their names. If that doesn’t work, then layer’s relative position will be used.

Defaults to names_or_order.

skip_validation : bool

When set to False validation will be applied per each layer in order to make sure that there were no changes between created and stored models. Defaults to True

Raises:
ValueError

Happens in case if ignore_missing=False and there is no parameters for some of the layers.

Examples

>>> from neupy import layers, storage
>>>
>>> network = layers.Input(10) > layers.Softmax(3)
>>> storage.load_hdf5(network, '/path/to/parameters.hdf5')
neupy.storage.save_pickle(network, filepath, python_compatible=False)[source]

Save layer parameters in pickle file.

Parameters:
network : network, list of layer or network
filepath : str

Path to the pickle file that stores network parameters.

python_compatible : bool

If True pickled object would be compatible with Python 2 and 3 (pickle protocol equal to 2). If False then value would be pickled as highest protocol (pickle.HIGHEST_PROTOCOL). Defaults to False.

Examples

>>> from neupy import layers, storage
>>>
>>> network = layers.Input(10) > layers.Softmax(3)
>>> storage.save_pickle(network, '/path/to/parameters.pickle')
neupy.storage.load_pickle(network, filepath, ignore_missing=False, load_by='names_or_order', skip_validation=True)[source]

Load and set parameters for layers from the specified filepath.

Parameters:
network : network, list of layer or network
filepath : str

Path to pickle file that will store network parameters.

ignore_missing : bool

False means that error will be triggered in case if some of the layers doesn’t have storage parameters in the specified source. Defaults to False.

load_by : {names, order, names_or_order}

Defines strategy that will be used during parameter loading

  • names - Matches layers using their names.
  • order - Matches layers using their relative position.
  • names_or_order - First, method tries to match layers using their names. If that doesn’t work, then layer’s relative position will be used.

Defaults to names_or_order.

skip_validation : bool

When set to False validation will be applied per each layer in order to make sure that there were no changes between created and stored models. Defaults to True

Raises:
ValueError

Happens in case if ignore_missing=False and there is no parameters for some of the layers.

Examples

>>> from neupy import layers, storage
>>>
>>> network = layers.Input(10) > layers.Softmax(3)
>>> storage.load_pickle(network, '/path/to/parameters.pickle')
neupy.storage.save_json(network, filepath, indent=None)[source]

Save network parameters in JSON format.

Parameters:
network : network, list of layer or network
filepath : str

Path to the JSON file that stores network parameters.

indent : int or None

Indentation that would be specified for the output JSON. Intentation equal to 2 or 4 makes it easy to read raw text files. The None value disables indentation which means that everything will be stored compactly. Defaults to None.

Examples

>>> from neupy import layers, storage
>>>
>>> network = layers.Input(10) > layers.Softmax(3)
>>> storage.save_json(network, '/path/to/parameters.json')
neupy.storage.load_json(network, filepath, ignore_missing=False, load_by='names_or_order', skip_validation=True)[source]

Load network parameters from JSON file.

Parameters:
network : network, list of layer or network
filepath : str

Path to JSON file that will store network parameters.

ignore_missing : bool

False means that error will be triggered in case if some of the layers doesn’t have storage parameters in the specified source. Defaults to False.

load_by : {names, order, names_or_order}

Defines strategy that will be used during parameter loading

  • names - Matches layers using their names.
  • order - Matches layers using their relative position.
  • names_or_order - First, method tries to match layers using their names. If that doesn’t work, then layer’s relative position will be used.

Defaults to names_or_order.

skip_validation : bool

When set to False validation will be applied per each layer in order to make sure that there were no changes between created and stored models. Defaults to True

Raises:
ValueError

Happens in case if ignore_missing=False and there is no parameters for some of the layers.

Examples

>>> from neupy import layers, storage
>>>
>>> network = layers.Input(10) > layers.Softmax(3)
>>> storage.load_json(network, '/path/to/parameters.json')
neupy.storage.save_hdf5(network, filepath)[source]

Save network parameters in HDF5 format.

Parameters:
network : network, list of layer or network
filepath : str

Path to the HDF5 file that stores network parameters.

Examples

>>> from neupy import layers, storage
>>>
>>> network = layers.Input(10) > layers.Softmax(3)
>>> storage.save_hdf5(network, '/path/to/parameters.hdf5')
neupy.storage.load_hdf5(network, filepath, ignore_missing=False, load_by='names_or_order', skip_validation=True)[source]

Load network parameters from HDF5 file.

Parameters:
network : network, list of layer or network
filepath : str

Path to HDF5 file that will store network parameters.

ignore_missing : bool

False means that error will be triggered in case if some of the layers doesn’t have storage parameters in the specified source. Defaults to False.

load_by : {names, order, names_or_order}

Defines strategy that will be used during parameter loading

  • names - Matches layers using their names.
  • order - Matches layers using their relative position.
  • names_or_order - First, method tries to match layers using their names. If that doesn’t work, then layer’s relative position will be used.

Defaults to names_or_order.

skip_validation : bool

When set to False validation will be applied per each layer in order to make sure that there were no changes between created and stored models. Defaults to True

Raises:
ValueError

Happens in case if ignore_missing=False and there is no parameters for some of the layers.

Examples

>>> from neupy import layers, storage
>>>
>>> network = layers.Input(10) > layers.Softmax(3)
>>> storage.load_hdf5(network, '/path/to/parameters.hdf5')
neupy.storage.load_dict(network, data, ignore_missing=False, load_by='names_or_order', skip_validation=True)[source]

Load network networks from dictionary.

Parameters:
network : network, list of layer or network
data : dict

Dictionary that stores network parameters.

ignore_missing : bool

False means that error will be triggered in case if some of the layers doesn’t have storage parameters in the specified source. Defaults to False.

load_by : {names, order, names_or_order}

Defines strategy that will be used during parameter loading

  • names - Matches layers using their names.
  • order - Matches layers using their relative position.
  • names_or_order - First, method tries to match layers using their names. If that doesn’t work, then layer’s relative position will be used.

Defaults to names_or_order.

skip_validation : bool

When set to False validation will be applied per each layer in order to make sure that there were no changes between created and stored models. Defaults to True

Raises:
ValueError

Happens in case if ignore_missing=False and there is no parameters for some of the layers.

neupy.storage.save_dict(network)[source]

Save network into the dictionary.

Parameters:
network : network, list of layer or network
Returns:
dict

Saved parameters and information about network in dictionary using specific format. Learn more about the NeuPy’s storage format in the official documentation.

Examples

>>> from neupy import layers, storage
>>>
>>> network = layers.Input(10) >> layers.Softmax(3)
>>> layers_data = storage.save_dict(network)
>>>
>>> layers_data.keys()
['layers', 'graph', 'metadata']