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)
import argparse import os.path import sys import time import numpy as np from six.moves import xrange # pylint: disable=redefined-builtin import tensorflow as tf import logging from tensorflow.contrib.framework.python.ops import audio_ops as contrib_audio from datetime import datetime from tensorflow.python.platform import gfile from speechclas import paths, config, input_data, models, freeze, utils, model_utils from tensorflow.python.framework import graph_util CONF = config.conf_dict() timestamp = datetime.now().strftime('%Y-%m-%d_%H%M%S') def train_fn(TIMESTAMP, CONF): sess = tf.InteractiveSession() paths.timestamp = TIMESTAMP paths.CONF = CONF print(CONF) utils.create_dir_tree() #Activate only if you want to make a backup of the splits used for the training #utils.backup_splits() # logging.set_verbosity(logging.INFO)