def init(config_filename, cmd_line_opts, dataset_config_str): """ :param str config_filename: global config for CRNN :param list[str] cmd_line_opts: options for init_config method :param str dataset_config_str: dataset via init_dataset_via_str() """ rnn.init_better_exchook() rnn.init_thread_join_hack() if config_filename: rnn.init_config(config_filename, cmd_line_opts) rnn.init_log() else: log.initialize(verbosity=[5]) print("Returnn hdf_dump starting up.", file=log.v3) rnn.init_faulthandler() if config_filename: rnn.init_data() rnn.print_task_properties() assert isinstance(rnn.train_data, Dataset) dataset = rnn.train_data else: assert dataset_config_str dataset = init_dataset(dataset_config_str) print("Source dataset:", dataset.len_info(), file=log.v3) return dataset
def init(config_filename, log_verbosity): """ :param str config_filename: filename to config-file :param int log_verbosity: """ rnn.init_better_exchook() rnn.init_thread_join_hack() if config_filename: print("Using config file %r." % config_filename) assert os.path.exists(config_filename) rnn.init_config(config_filename=config_filename, command_line_options=[]) global config config = rnn.config config.set("task", "calculate_wer") config.set("log", None) config.set("log_verbosity", log_verbosity) config.set("use_tensorflow", True) rnn.init_log() print("Returnn calculate-word-error-rate starting up.", file=log.v1) rnn.returnn_greeting() rnn.init_backend_engine() assert Util.BackendEngine.is_tensorflow_selected( ), "this is only for TensorFlow" rnn.init_faulthandler() rnn.init_config_json_network() rnn.print_task_properties()
def init(config_filename, cmd_line_opts, dataset_config_str): """ :param str config_filename: global config for CRNN :param list[str] cmd_line_opts: options for init_config method :param str dataset_config_str: dataset via init_dataset_via_str() """ rnn.init_better_exchook() rnn.init_thread_join_hack() if config_filename: rnn.init_config(config_filename, cmd_line_opts) rnn.init_log() else: log.initialize(verbosity=[5]) print("Returnn hdf_dump starting up.", file=log.v3) rnn.init_faulthandler() if config_filename: rnn.init_data() rnn.print_task_properties() assert isinstance(rnn.train_data, Dataset) dataset = rnn.train_data else: assert dataset_config_str dataset = init_dataset(dataset_config_str) print("Source dataset:", dataset.len_info(), file=log.v3) return dataset
def init(config_str, verbosity): """ :param str config_str: either filename to config-file, or dict for dataset :param int verbosity: """ rnn.init_better_exchook() rnn.init_thread_join_hack() datasetDict = None configFilename = None if config_str.strip().startswith("{"): print("Using dataset %s." % config_str) datasetDict = eval(config_str.strip()) elif config_str.endswith(".hdf"): datasetDict = {"class": "HDFDataset", "files": [config_str]} print("Using dataset %r." % datasetDict) assert os.path.exists(config_str) else: configFilename = config_str print("Using config file %r." % configFilename) assert os.path.exists(configFilename) rnn.init_config(config_filename=configFilename, default_config={"cache_size": "0"}) global config config = rnn.config config.set("log", None) config.set("log_verbosity", verbosity) if datasetDict: config.set("train", datasetDict) rnn.init_log() print("Returnn dump-dataset starting up.", file=log.v2) rnn.returnn_greeting() rnn.init_faulthandler() rnn.init_config_json_network() rnn.init_data() rnn.print_task_properties()
def init(config_str, verbosity): """ :param str config_str: either filename to config-file, or dict for dataset :param int verbosity: """ rnn.init_better_exchook() rnn.init_thread_join_hack() datasetDict = None configFilename = None if config_str.strip().startswith("{"): print("Using dataset %s." % config_str) datasetDict = eval(config_str.strip()) elif config_str.endswith(".hdf"): datasetDict = {"class": "HDFDataset", "files": [config_str]} print("Using dataset %r." % datasetDict) assert os.path.exists(config_str) else: configFilename = config_str print("Using config file %r." % configFilename) assert os.path.exists(configFilename) rnn.init_config(config_filename=configFilename, default_config={"cache_size": "0"}) global config config = rnn.config config.set("log", None) config.set("log_verbosity", verbosity) if datasetDict: config.set("train", datasetDict) rnn.init_log() print("Returnn dump-dataset starting up.", file=log.v2) rnn.returnn_greeting() rnn.init_faulthandler() rnn.init_config_json_network() rnn.init_data() rnn.print_task_properties()
def init(configFilename, commandLineOptions): rnn.init_better_exchook() rnn.init_thread_join_hack() rnn.init_config(configFilename, commandLineOptions) global config config = rnn.config rnn.init_log() print("CRNN demo-dataset starting up", file=log.v3) rnn.init_faulthandler() rnn.init_config_json_network() rnn.init_data() rnn.print_task_properties()
def init(configFilename=None): rnn.init_better_exchook() rnn.init_thread_join_hack() if configFilename: rnn.init_config(configFilename, command_line_options=[]) rnn.init_log() else: log.initialize() print("Returnn collect-words starting up.", file=log.v3) rnn.init_faulthandler() if configFilename: rnn.init_config_json_network() rnn.init_data() rnn.print_task_properties()
def init(configFilename=None): rnn.init_better_exchook() rnn.init_thread_join_hack() if configFilename: rnn.init_config(configFilename, command_line_options=[]) rnn.init_log() else: log.initialize() print("Returnn collect-words starting up.", file=log.v3) rnn.init_faulthandler() if configFilename: rnn.init_config_json_network() rnn.init_data() rnn.print_task_properties()
def _init_base(configfile=None, target_mode=None, epoch=None, sprint_opts=None): """ :param str|None configfile: filename, via init(), this is set :param str|None target_mode: "forward" or so. via init(), this is set :param int epoch: via init(), this is set :param dict[str,str]|None sprint_opts: optional parameters to override values in configfile """ global isInitialized isInitialized = True # Run through in any case. Maybe just to set targetMode. if not getattr(sys, "argv", None): # Set some dummy. Some code might want this (e.g. TensorFlow). sys.argv = [__file__] global config if not config: # Some subset of what we do in rnn.init(). rnn.init_better_exchook() rnn.init_thread_join_hack() if configfile is None: configfile = DefaultSprintCrnnConfig assert os.path.exists(configfile) rnn.init_config(config_filename=configfile, extra_updates={"task": target_mode}) assert rnn.config config = rnn.config if sprint_opts is not None: config.update(sprint_opts) rnn.init_log() rnn.returnn_greeting(config_filename=configfile) rnn.init_backend_engine() rnn.init_faulthandler(sigusr1_chain=True) rnn.init_config_json_network() global Engine if BackendEngine.is_tensorflow_selected(): # Use TFEngine.Engine class instead of Engine.Engine. from TFEngine import Engine elif BackendEngine.is_theano_selected(): from Engine import Engine import atexit atexit.register(_at_exit_handler) if target_mode: set_target_mode(target_mode) _init_dataset() if target_mode and target_mode == "forward" and epoch: model_filename = config.value('model', '') fns = [ EngineBase.epoch_model_filename(model_filename, epoch, is_pretrain) for is_pretrain in [False, True] ] fn_postfix = "" if BackendEngine.is_tensorflow_selected(): fn_postfix += ".meta" fns_existing = [fn for fn in fns if os.path.exists(fn + fn_postfix)] assert len(fns_existing) == 1, "%s not found" % fns model_epoch_filename = fns_existing[0] config.set('load', model_epoch_filename) assert EngineBase.get_epoch_model(config)[1] == model_epoch_filename, ( "%r != %r" % (EngineBase.get_epoch_model(config), model_epoch_filename)) global engine if not engine: devices = rnn.init_theano_devices() rnn.print_task_properties(devices) rnn.init_engine(devices) engine = rnn.engine assert isinstance(engine, Engine)
def _init_base(configfile=None, target_mode=None, epoch=None, sprint_opts=None): """ :param str|None configfile: filename, via init(), this is set :param str|None target_mode: "forward" or so. via init(), this is set :param int epoch: via init(), this is set :param dict[str,str]|None sprint_opts: optional parameters to override values in configfile """ global isInitialized isInitialized = True # Run through in any case. Maybe just to set targetMode. if not getattr(sys, "argv", None): # Set some dummy. Some code might want this (e.g. TensorFlow). sys.argv = [__file__] global config if not config: # Some subset of what we do in rnn.init(). rnn.init_better_exchook() rnn.init_thread_join_hack() if configfile is None: configfile = DefaultSprintCrnnConfig assert os.path.exists(configfile) rnn.init_config(config_filename=configfile, extra_updates={"task": target_mode}) config = rnn.config if sprint_opts is not None: config.update(sprint_opts) rnn.init_log() rnn.returnn_greeting(config_filename=configfile) rnn.init_backend_engine() rnn.init_faulthandler(sigusr1_chain=True) rnn.init_config_json_network() global Engine if BackendEngine.is_tensorflow_selected(): # Use TFEngine.Engine class instead of Engine.Engine. from TFEngine import Engine elif BackendEngine.is_theano_selected(): from Engine import Engine import atexit atexit.register(_at_exit_handler) if target_mode: set_target_mode(target_mode) _init_dataset() if target_mode and target_mode == "forward" and epoch: model_filename = config.value('model', '') fns = [EngineBase.epoch_model_filename(model_filename, epoch, is_pretrain) for is_pretrain in [False, True]] fn_postfix = "" if BackendEngine.is_tensorflow_selected(): fn_postfix += ".meta" fns_existing = [fn for fn in fns if os.path.exists(fn + fn_postfix)] assert len(fns_existing) == 1, "%s not found" % fns model_epoch_filename = fns_existing[0] config.set('load', model_epoch_filename) assert EngineBase.get_epoch_model(config)[1] == model_epoch_filename, ( "%r != %r" % (EngineBase.get_epoch_model(config), model_epoch_filename)) global engine if not engine: devices = rnn.init_theano_devices() rnn.print_task_properties(devices) rnn.init_engine(devices) engine = rnn.engine assert isinstance(engine, Engine)