motornet.nets.models#
- class motornet_tf.nets.models.DistalTeacher(*args, **kwargs)#
Bases:
Model
,ABC
This is a custom
tensorflow.keras.Model
object, whose purpose is to enable savingmotornet.plants
object configuration when saving the model as well.In Tensorflow,
tensorflow.keras.Model
objects group layers into an object with training and inference features. See the Tensorflow documentation for more details on how to declare, compile and use use atensorflow.keras.Model
object.Conceptually, as this model class performs backward propagation through the plant (which can be considered a perfect forward model), this class essentially performs the training of the controller using a distal teacher algorithm, as defined in [1].
References
[1] Jordan MI, Rumelhart DE. Forward Models: Supervised Learning with a Distal Teacher. Cognitive Science, 1992 Jul;16(3):307-354. doi: 10.1207/s15516709cog1603_1.
- Parameters:
inputs – A
tensorflow.keras.layers.Input`
object or list oftensorflow.keras.layers.Input
objects that will serve as tensor placeholder input(s) to the model.outputs – The output(s) of the model. See motornet tutorial on how to build a model, and the introduction section of the Functional API example in the Tensorflow documentation for more information about this argument: https://www.tensorflow.org/guide/keras/functional#introduction.
task – A
motornet.tasks.Task
object class or subclass.name – String, the name of the model.
- classmethod from_config(config, custom_objects=None)#
Creates a layer from its config.
This method is the reverse of get_config, capable of instantiating the same layer from the config dictionary. It does not handle layer connectivity (handled by Network), nor weights (handled by set_weights).
- Parameters:
config – A Python dictionary, typically the output of get_config.
- Returns:
A layer instance.
- get_config()#
Gets the model’s configuration.
- Returns:
A dictionary containing the model’s configuration. This includes the task object passed at initialization.
- save_model(path, **kwargs)#
Gets the model’s configuration as a dictionary and then save it into a JSON file.
- Parameters:
path –
String, the absolute path to the JSON file that will be produced. The name of the JSON file itself should be included, without the extension. For instance, if we want to create a JSON file called my_model_config.json in ~/path/to/desired/directory, we would call this method in the python console like so:
model.save_model("~/path/to/desired/directory/my_model_config")
**kwargs – Not used here, this is for subclassing compatibility only.
- train_step(data)#
The logic for one training step. Compared to the default method, this overriding method allows for recomputation of targets online (during movement), in addition to essentially reproducing what the default method does.
Warning
Some features from the original
tensorflow.keras.Model.train_step()
method are not implemented here.Outputing metrics as a list instead of a dictionary, since motornet always uses dictionaries
The sample weighting functionality, since data in motornet is usually synthetic and not empirical, meaning there is usually no bias in sample representation.
- Parameters:
data – A nested structure of tensor arrays.
- Returns:
A dictionary containing values that will be passed to
tf.keras.callbacks.CallbackList.on_train_batch_end()
. Typically, the values of the Model’s metrics are returned. Example: {‘loss’: 0.2, ‘accuracy’: 0.7}.
- class motornet_tf.nets.models.MotorNetModel(*args, **kwargs)#
Bases:
DistalTeacher
This is an alias name for the
DistalTeacher
class for backward compatibility.