Manual Model Upload

The example demonstrates Trains tracking of a manually configured model created with Keras, including model snapshots (checkpoint models), hyperparameters, and output to the console. When the script runs, it creates an experiment named Model configuration and upload, which is associated with the examples project.


This example shows two ways to connect a configuration, using the same Trains Python Client package method, Task.connect_configuration.

Connect a configuration file by calling the Task.connect_configuration method, providing the file's path. Trains Server stores a copy of the file.

# Connect a local configuration file
config_file = os.path.join('..', '..', 'reporting', 'data_samples', 'sample.json')
config_file = task.connect_configuration(config_file)

Or, create a configuration dictionary and call that same Task.connect_configuration method, providing the dictionary.

model_config_dict = {
    'value': 13.37,
    'dict': {'sub_value': 'string', 'sub_integer': 11},
    'list_of_ints': [1, 2, 3, 4],
model_config_dict = task.connect_configuration(model_config_dict)

If the configuration changes, Trains track it.

model_config_dict['new value'] = 10
model_config_dict['value'] *= model_config_dict['new value']

In the Trains Web (UI), the manually connected configuration appears in the ARTIFACTS tab, Input Model area.

You can see that new value is tracked. The configuration parameter value is 133.7 (10 its original value of 13.37), and the parameter new value is now in the configuration.

Trains stores the output model's configuration for the Keras Model built in the code.

In the Trains Web (UI), the output model's configuration appears in the ARTIFACTS tab, Output Model area.

This is the configuration of the model created in the example script.

def get_model():
    # Create a simple model.
    inputs = Input(shape=(32,))
    outputs = layers.Dense(1)(inputs)
    keras_model = Model(inputs, outputs)
    keras_model.compile(optimizer='adam', loss='mean_squared_error')
    return keras_model

It also appears in model details, the NETWORK tab.

Class label enumeration

To connect class label enumeration, create a dictionary of class labels and value, and then call the Task.connect_label_enumeration method, providing it the dictionary.

# store the label enumeration of the training model
labels = {'background': 0, 'cat': 1, 'dog': 2}

In the model details (which appear when you click the model name in the ARTIFACTS tab, Output Model area), you can see the class label enumeration in the LABELS tab.

Output model

Trains logs the following output model information:

  • The output model location (URL)
  • Model snapshots / checkpoint model locations (URLs)
  • The experiment creating the model
  • Other general information about the model.

These appear in the model details GENERAL tab., "model"))