fedn.utils package

Submodules

fedn.utils.checksum module

fedn.utils.checksum.sha(fname)[source]
Parameters:

fname

Returns:

fedn.utils.dispatcher module

class fedn.utils.dispatcher.Dispatcher(config, dir)[source]

Bases: object

run_cmd(cmd_type)[source]
Parameters:

cmd_type

fedn.utils.helpers module

class fedn.utils.helpers.HelperBase[source]

Bases: ABC

Abstract class defining helpers.

abstract get_tmp_path()[source]

Return a temporary output path compatible with save_model, load_model.

abstract increment_average(model, model_next, n)[source]

Compute one increment of incremental averaging. n: the iteration index 1…N in the sequence.

abstract load_model(path)[source]

Load the model save with save_model from disk on path.

abstract load_model_from_BytesIO(model_bytesio)[source]

Load a model from a BytesIO buffered object.

abstract save_model(model, path)[source]

Serialize the model to file on disk on path. The serialized model must be a single binary object.

abstract serialize_model_to_BytesIO(model)[source]

Serialize a model to a BytesIO buffered object.

fedn.utils.helpers.get_helper(helper_type)[source]

Return an instance of the helper class.

Parameters:

(str) (helper_type) – The helper type (‘keras’,’pytorch’)

Returns:

fedn.utils.kerashelper module

class fedn.utils.kerashelper.KerasHelper[source]

Bases: HelperBase

FEDn helper class for keras.Sequential.

average_weights(weights)[source]

Average weights of Keras Sequential models.

get_tmp_path()[source]

Return a temporary output path compatible with save_model, load_model.

get_weights(weights)[source]
Parameters:

weights

Returns:

increment_average(weights, weights_next, n)[source]

Update an incremental average.

load_model(path='weights.npz')[source]
Parameters:

path

Returns:

load_model_from_BytesIO(model_bytesio)[source]

Load a model from a BytesIO object.

save_model(weights, path=None)[source]
Parameters:
  • weights

  • path

Returns:

serialize_model_to_BytesIO(model)[source]
Parameters:

model

Returns:

set_weights(weights_, weights)[source]
Parameters:
  • weights

  • weights

fedn.utils.logger module

class fedn.utils.logger.Logger(log_level=10, to_file='', file_path='/home/runner/work/fedn/fedn')[source]

Bases: object

fedn.utils.numpyarrayhelper module

class fedn.utils.numpyarrayhelper.NumpyArrayHelper[source]

Bases: HelperBase

FEDn helper class for numpy arrays.

get_tmp_path()[source]

Return a temporary output path compatible with save_model, load_model.

increment_average(model, model_next, n)[source]

Update an incremental average.

load_model(path)[source]
Parameters:

path

Returns:

load_model_from_BytesIO(model_bytesio)[source]

Load a model from a BytesIO object.

save_model(model, path=None)[source]
Parameters:
  • model

  • path

Returns:

serialize_model_to_BytesIO(model)[source]
Parameters:

model

Returns:

fedn.utils.process module

fedn.utils.process.run_process(args, cwd)[source]
Parameters:
  • args

  • cwd

fedn.utils.pytorchhelper module

class fedn.utils.pytorchhelper.PytorchHelper[source]

Bases: HelperBase

get_tmp_path()[source]
Returns:

increment_average(model, model_next, n)[source]

Update an incremental average.

load_model(path='weights.npz')[source]
Parameters:

path

Returns:

load_model_from_BytesIO(model_bytesio)[source]

Load a model from a BytesIO object.

save_model(weights_dict, path=None)[source]
Parameters:
  • weights_dict

  • path

Returns:

serialize_model_to_BytesIO(model)[source]
Parameters:

model

Returns:

Module contents