2021-05-13 23:48:51 +00:00
---
title: Configuring Models
---
The [model_config.py ](https://github.com/allegroai/clearml/blob/master/examples/reporting/model_config.py ) example demonstrates
configuring a model and defining label enumeration. Connect the configuration and label enumeration to a Task and, once
2021-08-22 12:23:48 +00:00
connected, **ClearML** tracks any changes to them. When **ClearML** stores a model in any framework, **ClearML** stores
2021-05-13 23:48:51 +00:00
the configuration and label enumeration with it.
When the script runs, it creates an experiment named `Model configuration example` , which is associated with the `examples` project.
2021-09-09 10:17:46 +00:00
## Configuring Models
2021-05-13 23:48:51 +00:00
2021-09-09 10:17:46 +00:00
### Using a Configuration File
2021-05-13 23:48:51 +00:00
Connect a configuration file to a Task by calling the [Task.connect_configuration ](../../references/sdk/task.md#connect_configuration )
2021-08-22 12:23:48 +00:00
method with the file location and the configuration object's name as arguments. In this example, we connect a JSON file and a YAML file
to a Task.
2021-05-13 23:48:51 +00:00
2021-12-14 13:12:30 +00:00
```python
config_file_json = 'data_samples/sample.json'
task.connect_configuration(name="json file", configuration=config_file_json)
config_file_yaml = 'data_samples/config_yaml.yaml'
task.connect_configuration(configuration=config_file_yaml, name="yaml file")
```
2021-05-13 23:48:51 +00:00
2021-09-09 12:59:49 +00:00
The configuration is logged to the ClearML Task and can be viewed in the **ClearML Web UI** experiment details ** >** **CONFIGURATION** tab ** >** **CONFIGURATION OBJECTS**
2021-08-22 12:23:48 +00:00
section. The contents of the JSON file will appear in the **json file** object, and the contents of the YAML file will appear
in the **yaml file** object, as specified in the `name` parameter of the `connect_configuration` method.
![image ](../../img/examples_reporting_config.png )
2021-05-13 23:48:51 +00:00
2021-09-09 10:17:46 +00:00
### Configuration Dictionary
2021-05-13 23:48:51 +00:00
Connect a configuration dictionary to a Task by creating a dictionary, and then calling the [Task.connect_configuration ](../../references/sdk/task.md#connect_configuration )
2021-08-22 12:23:48 +00:00
method with the dictionary and the object name as arguments. After the configuration is connected, **ClearML** tracks changes to it.
2021-05-13 23:48:51 +00:00
2021-12-14 13:12:30 +00:00
```python
model_config_dict = {
'CHANGE ME': 13.37,
'dict': {'sub_value': 'string', 'sub_integer': 11},
'list_of_ints': [1, 2, 3, 4],
}
model_config_dict = task.connect_configuration(
name='dictionary',
configuration=model_config_dict
)
# Update the dictionary after connecting it, and the changes will be tracked as well.
model_config_dict['new value'] = 10
model_config_dict['CHANGE ME'] *= model_config_dict['new value']
```
2021-09-09 12:59:49 +00:00
The configurations are connected to the ClearML Task and can be viewed in the **ClearML Web UI** ** >** experiment details ** >** **CONFIGURATION** tab ** >**
2021-08-22 12:23:48 +00:00
**CONFIGURATION OBJECTS** area ** >** **dictionary** object.
2021-05-13 23:48:51 +00:00
2021-08-22 12:23:48 +00:00
![image ](../../img/examples_reporting_config_3.png )
2021-05-13 23:48:51 +00:00
2021-09-09 10:17:46 +00:00
## Label Enumeration
2021-05-13 23:48:51 +00:00
Connect a label enumeration dictionary by creating the dictionary, and then calling the [Task.connect_label_enumeration ](../../references/sdk/task.md#connect_label_enumeration )
method with the dictionary as an argument.
2021-12-14 13:12:30 +00:00
```python
# store the label enumeration of the training model
labels = {'background': 0, 'cat': 1, 'dog': 2}
task.connect_label_enumeration(labels)
```
2021-05-13 23:48:51 +00:00
2021-08-22 12:23:48 +00:00
Log a local model file.
2021-12-14 13:12:30 +00:00
```python
OutputModel().update_weights('my_best_model.bin')
```
2021-08-22 12:23:48 +00:00
The model which is stored contains the model configuration and the label enumeration.
![image ](../../img/examples_reporting_config_2.png )