def train(user_conf): """ Parameters ---------- user_conf : dict Json dict (created with json.dumps) with the user's configuration parameters that will replace the defaults. Must be loaded with json.loads() For example: user_conf={'num_classes': 'null', 'lr_step_decay': '0.1', 'lr_step_schedule': '[0.7, 0.9]', 'use_early_stopping': 'false'} """ CONF = config.CONF # Update the conf with the user input for group, val in sorted(CONF.items()): for g_key, g_val in sorted(val.items()): g_val['value'] = json.loads(user_conf[g_key]) # Check the configuration try: config.check_conf(conf=CONF) except Exception as e: raise BadRequest(e) CONF = config.conf_dict(conf=CONF) timestamp = datetime.now().strftime('%Y-%m-%d_%H%M%S') config.print_conf_table(CONF) K.clear_session() # remove the model loaded for prediction train_fn(TIMESTAMP=timestamp, CONF=CONF) # Sync with NextCloud folders (if NextCloud is available) try: mount_nextcloud(paths.get_models_dir(), 'ncplants:/models') except Exception as e: print(e)
def update_with_query_conf(user_args): """ Update the default YAML configuration with the user's input args from the API query """ # Update the default conf with the user input CONF = config.CONF for group, val in sorted(CONF.items()): for g_key, g_val in sorted(val.items()): if g_key in user_args: g_val['value'] = json.loads(user_args[g_key]) # Check and save the configuration config.check_conf(conf=CONF) config.conf_dict = config.get_conf_dict(conf=CONF)
def update_with_saved_conf(saved_conf): """ Update the default YAML configuration with the configuration saved from training """ # Update the default conf with the user input CONF = config.CONF for group, val in sorted(CONF.items()): if group in saved_conf.keys(): for g_key, g_val in sorted(val.items()): if g_key in saved_conf[group].keys(): g_val['value'] = saved_conf[group][g_key] # Check and save the configuration config.check_conf(conf=CONF) config.conf_dict = config.get_conf_dict(conf=CONF)