Python API
DataStore
class DataStore()
__init__
| __init__(location="http://localhost:3030")
DataStores enable communication with Marcelle Backends. DataStores provide access to services registered on a backend at the specified location.
Arguments:
locationstr, optional - Backend URL. Defaults to "http://localhost:3030".
.service()
| service(name)
Access a service by name
Arguments:
namestr - service name
Returns:
Service- Marcelle Service object.
Service
class Service()
__init__
| __init__(location)
Services provide an interface to interact with data stored in Marcelle backend. Since Marcelle backends are based on Feathers.js (https://crow.docs.feathersjs.com/), services provide a similar API with predefined CRUD methods.
Arguments:
locationstr - Service location URL.
.find()
| find(params={})
Retrieves a list of all resources from the service. params.query can be used to filter and limit the returned data.
Arguments:
paramsdict, optional - contain additional information for the service method call. See httpscrow.๐/docs.feathersjs.com/api/services.html#params Defaults to {}.
Returns:
dict- A dictionary containing the response. Data is paginated by default. see httpscrow.๐/docs.feathersjs.com/api/services.html#params
.get()
| get(id, params={})
Retrieves a single resource with the given id from the service.
Arguments:
idstr - unique identifier of the ressourceparamsdict, optional - contain additional information for the service method call. See httpscrow.๐/docs.feathersjs.com/api/services.html#params Defaults to {}.
Returns:
dict- the requested item as a dictionary
.create()
| create(data, params={})
Creates a new resource with data. The method should return with the newly created data. data may also be an array.
Arguments:
datadict - ressource data as a JSON-serializable dictionaryparamsdict, optional - contain additional information for the service method call. See httpscrow.๐/docs.feathersjs.com/api/services.html#params Defaults to {}.
Returns:
dict- the created ressource
.update()
| update(id, data, params={})
Replaces the resource identified by id with data. The method should return with the complete, updated resource data. id can also be null when updating multiple records, with params.query containing the query criteria.
Arguments:
idstr - unique identifier of the ressourcedatadict - ressource data as a JSON-serializable dictionaryparamsdict, optional - contain additional information for the service method call. See httpscrow.๐/docs.feathersjs.com/api/services.html#params Defaults to {}.
Returns:
dict- updated resource data
.patch()
| patch(id, data, params={})
Merges the existing data of the resource identified by id with the new data. id can also be null indicating that multiple resources should be patched with params.query containing the query criteria.
Arguments:
idstr - unique identifier of the ressourcedatadict - partial ressource data as a JSON-serializable dictionaryparamsdict, optional - contain additional information for the service method call. See httpscrow.๐/docs.feathersjs.com/api/services.html#params Defaults to {}.
Returns:
dict- updated resource data
.remove()
| remove(id, params={})
Removes the resource with id. The method should return with the removed data. id can also be null, which indicates the deletion of multiple resources, with params.query containing the query criteria.
Arguments:
idstr - unique identifier of the ressourceparamsdict, optional - contain additional information for the service method call. See httpscrow.๐/docs.feathersjs.com/api/services.html#params Defaults to {}.
Returns:
dict- the removed data
.items()
| items(query={})
Returns an iterator over the service data, given an optional query. See feathers documentation for querying: httpscrow.๐/docs.feathersjs.com/api/databases/querying.html
Arguments:
querydict, optional - Optional query. See httpscrow.๐/docs.feathersjs.com/api/databases/querying.html. Defaults to {}.
Yields:
dict- service ressource
Remote
class Remote()
__init__
| __init__(backend_root="http://localhost:3030", save_format="tfjs", source="keras")
The remote manager for Marcelle allows to save run information and upload model checkpoints and assets to a Marcelle backend
Arguments:
backend_rootstr, optional - The backend's root URL. Defaults to "http://localhost:3030".save_formatstr, optional - Format used to upload the models to the backend. Can be either "tfjs" or "onnx". Defaults to "tfjs".sourcestr, optional - Source framework name. Only "keras" is currently fully supported. Defaults to "keras".
.create()
| create(run_data)
Create a new training run, and upload it on the server
Arguments:
run_datadict, optional - Run data as a JSON-serializable dictionary.TODO- Document "run_data" format (@see Writer)
.update()
| update(run_data=None)
Update the run data, and upload it on the server
Arguments:
run_datadict, optional - Run data as a JSON-serializable dictionary.
.upload_model()
| upload_model(path_to_model, local_format, metadata={})
Upload a model checkpoint to the backend server
Arguments:
path_to_modelstring - local path to the model fileslocal_formatstring - format of the saved model. Can be "h5 or "save_model".metadatadict, optional - Optional metadata to save with the model. Defaults to {}.
Raises:
Exception- When local and remote formats are Unsupported
Returns:
dict- The stored model's information from the backend
.upload_tfjs_model()
| upload_tfjs_model(tmp_path, metadata={})
Upload a TFJS model checkpoint to the backend server
Arguments:
tmp_pathstring - local path to the temporary model filesmetadatadict, optional - Optional metadata to save with the model. Defaults to {}.
Returns:
dict- The stored model's information from the backend
.upload_onnx_model()
| upload_onnx_model(tmp_path, metadata={})
Upload an ONNX model checkpoint to the backend server
Arguments:
tmp_pathstring - local path to the temporary model filesmetadatadict, optional - Optional metadata to save with the model. Defaults to {}.
Returns:
dict- The stored model's information from the backend
.upload_asset()
| upload_asset(path_to_asset, metadata={})
Upload an asset to the backend server. Assets are files of arbitrary format (images, sound files, ...)
Arguments:
path_to_assetstring - local path to the asset filemetadatadict, optional - Optional metadata to save with the asset. Defaults to {}.
Returns:
dict- The stored assets's information from the backend
.retrieve_run()
| retrieve_run(run_start_at)
Retrieve a training run from the backend using its starting date
Arguments:
run_start_atstring - Starting date of the run
Returns:
dict- The run data if it was found on the server, False otherwise
.remove_run()
| remove_run(run_data)
Remove a given run from the server, along with the associated checkpoints and assets.
Arguments:
run_datadict - Run data to be removed. Must have "_id" and "checkpoints" fields
Returns:
bool- wether the run was successfully removed
Uploader
class Uploader()
__init__
| __init__(remote)
The Uploader class alows to upload the results of a locally stored training run to the backend.
Arguments:
remoteRemote - An instance of Remote classTODO- Implement asset uploading
.upload()
| upload(run_directory, overwrite=False)
Upload a training run from a directory
Arguments:
run_directorystring - run directory, from a Writer or Keras callbackoverwritebool, optional - If True, overwrites the data on the server, replacing run information and checkpoints. Defaults to False.
Raises:
Exception- If the input directory does not exist
KerasCallback
class KerasCallback(tf.keras.callbacks.Callback)
__init__
| __init__(name, backend_root="http://localhost:3030", disk_save_format="h5", remote_save_format="tfjs", model_checkpoint_freq=None, base_log_dir="marcelle-logs", run_params={})
A Keras Callback to store training information in a Marcelle backend and locally.
Arguments:
namestr - The base name for the run.backend_rootstr, optional - The backend's root URL. Defaults to "http://localhost:3030".disk_save_formatstr, optional - Format used to store the models locally. Can be either "saved_model" or "h5". Defaults to "h5".remote_save_formatstr, optional - Format used to upload the models to the backend. Can be either "tfjs" or "onnx". Defaults to "tfjs".model_checkpoint_freqnumber, optional - The frequency at which checkpoints should be saved (in epochs). Defaults to None.base_log_dirstr, optional - Path to the directory where runs should be stored. Defaults to "marcelle-logs".run_paramsdict, optional - A dictionary of parameters associated with the training run (e.g. hyperparameters). Defaults to {}.
utils
conform_dict
conform_dict(d)
Normalize a dictionary for JSON serialization, casting numpy types
Arguments:
ddict - Input dictionary
Returns:
dict- Normalized dictionary
get_model_info
get_model_info(model, source, loss=None)
Get information about a Keras Model
Arguments:
model- an instance ofkeras.Modelsourcestring - The source framework (onlykerasis currently supported)lossstring or loss function, optional - Loss function used for training. Defaults to None.
Raises:
Exception- When another source thankerasis used
Returns:
dict- Keras model information
Writer
class Writer()
__init__
| __init__(name, backend_root="http://localhost:3030", disk_save_format="h5", remote_save_format="tfjs", base_log_dir="marcelle-logs", source="keras")
The Writer class allows to save training information locally and to a backend
Arguments:
namestr - The base name for the run.backend_rootstr, optional - The backend's root URL. Defaults to "http://localhost:3030".disk_save_formatstr, optional - Format used to store the models locally. Can be either "saved_model" or "h5". Defaults to "h5".remote_save_formatstr, optional - Format used to upload the models to the backend. Can be either "tfjs" or "onnx". Defaults to "tfjs".base_log_dirstr, optional - Path to the directory where runs should be stored. Defaults to "marcelle-logs".sourcestr, optional - Source framework name. Only "keras" is currently fully supported. Defaults to "keras".TODO- take a remote instance as argument (as for uploader), and make it optionalTODO- make Keras model optional
.create_run()
| create_run(model=None, run_params={}, loss=None)
Create a new training run
Arguments:
modelkeras.Model, optional - A keras.Model instance associated with the training run_params (dict, optional): A dictionary of parameters associated with the training run (e.g. hyperparameters). Defaults to {}.lossstring or loss function, optional - The loss function used for training. Defaults to None.
.train_begin()
| train_begin(epochs)
Signal that the training has started
Arguments:
epochsnumber - The total number of expected training epochs
.save_epoch()
| save_epoch(epoch, logs=None, save_checkpoint=False, assets=[])
Save the results at the end of an epoch, with optional associated checkpoint and assets
Arguments:
epochnumber - the epochlogsdict, optional - A dictionary of log values to record for the current epochs. The information should only concern the current epoch (for instance, logs for loss values should be scalar:- ``{"loss"
- 3.14}). Defaults to None. save_checkpointbool, optional - IfTrue, a checkpoint will be saved locally and uploaded to the backend, according to the formats specified in the constructor. Defaults to False.assetslist[string], optional - A list of assets paths associated with the epoch to upload. Defaults to [].
.train_end()
| train_end(logs=None, save_checkpoint=False)
Signal that the training has ended
Arguments:
logsdict, optional - Dictionary of logs (UNUSED?). Defaults to None.save_checkpointbool, optional - IfTrue, a checkpoint will be saved locally and uploaded to the backend, according to the formats specified in the constructor. Defaults to False.