mirror of
https://github.com/clearml/clearml
synced 2025-06-26 18:16:07 +00:00
Add Task connect_configuration, connect_label_enumeration, and support for nested dictionary with connect
Add Task.get_tasks
This commit is contained in:
@@ -12,22 +12,32 @@ task = Task.init(project_name='examples', task_name='Manual model configuration'
|
||||
# create a model
|
||||
model = torch.nn.Module
|
||||
|
||||
# store dictionary of definition for a specific network design
|
||||
# Connect a local configuration file
|
||||
config_file = 'samples/sample.json'
|
||||
config_file = task.connect_configuration(config_file)
|
||||
# then read configuration as usual, the backend will contain a copy of it.
|
||||
# later when executing remotely, the returned `config_file` will be a temporary file
|
||||
# containing a new copy of the configuration retrieved form the backend
|
||||
# # model_config_dict = json.load(open(config_file, 'rt'))
|
||||
|
||||
# Or Store dictionary of definition for a specific network design
|
||||
model_config_dict = {
|
||||
'value': 13.37,
|
||||
'dict': {'sub_value': 'string'},
|
||||
'dict': {'sub_value': 'string', 'sub_integer': 11},
|
||||
'list_of_ints': [1, 2, 3, 4],
|
||||
}
|
||||
task.set_model_config(config_dict=model_config_dict)
|
||||
model_config_dict = task.connect_configuration(model_config_dict)
|
||||
|
||||
# or read form a config file (this will override the previous configuration dictionary)
|
||||
# task.set_model_config(config_text='this is just a blob\nof text from a configuration file')
|
||||
# We now update the dictionary after connecting it, and the changes will be tracked as well.
|
||||
model_config_dict['new value'] = 10
|
||||
model_config_dict['value'] *= model_config_dict['new value']
|
||||
|
||||
# store the label enumeration the model is training for
|
||||
task.set_model_label_enumeration({'background': 0, 'cat': 1, 'dog': 2})
|
||||
print('Any model stored from this point onwards, will contain both model_config and label_enumeration')
|
||||
# store the label enumeration of the training model
|
||||
labels = {'background': 0, 'cat': 1, 'dog': 2}
|
||||
task.connect_label_enumeration(labels)
|
||||
|
||||
# storing the model, it will have the task network configuration and label enumeration
|
||||
print('Any model stored from this point onwards, will contain both model_config and label_enumeration')
|
||||
|
||||
torch.save(model, os.path.join(gettempdir(), "model"))
|
||||
print('Model saved')
|
||||
|
||||
8
examples/samples/sample.json
Normal file
8
examples/samples/sample.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"list_of_ints": [1,2,3,4],
|
||||
"dict": {
|
||||
"sub_value": "string",
|
||||
"sub_integer": 11
|
||||
},
|
||||
"value": 13.37
|
||||
}
|
||||
Reference in New Issue
Block a user