def debug_shell(user_ns=None, user_global_ns=None, exit_afterwards=True): print("Debug shell:") from Util import ObjAsDict import DebugHelpers user_global_ns_new = dict(ObjAsDict(DebugHelpers).items()) if user_global_ns: user_global_ns_new.update( user_global_ns) # may overwrite vars from DebugHelpers user_global_ns_new["debug"] = DebugHelpers # make this available always print("Available debug functions/utils (via DebugHelpers):") for k, v in sorted(vars(DebugHelpers).items()): if k[:1] == "_": continue print(" %s (%s)" % (k, type(v))) print("Also DebugHelpers available as 'debug'.") if not user_ns: user_ns = {} if user_ns: print("Locals:") for k, v in sorted(user_ns.items()): print(" %s (%s)" % (k, type(v))) import better_exchook better_exchook.debug_shell(user_ns, user_global_ns_new) if exit_afterwards: print("Debug shell exit. Exit now.") sys.exit(1)
def debug_shell(user_ns=None, user_global_ns=None, exit_afterwards=True): """ Provides some interactive Python shell. Uses IPython if possible. Wraps to ``better_exchook.debug_shell``. :param dict[str]|None user_ns: :param dict[str]|None user_global_ns: :param bool exit_afterwards: will do sys.exit(1) at the end """ print("Debug shell:") from Util import ObjAsDict import DebugHelpers user_global_ns_new = dict(ObjAsDict(DebugHelpers).items()) if user_global_ns: user_global_ns_new.update( user_global_ns) # may overwrite vars from DebugHelpers user_global_ns_new["debug"] = DebugHelpers # make this available always print("Available debug functions/utils (via DebugHelpers):") for k, v in sorted(vars(DebugHelpers).items()): if k[:1] == "_": continue print(" %s (%s)" % (k, type(v))) print("Also DebugHelpers available as 'debug'.") if not user_ns: user_ns = {} if user_ns: print("Locals:") for k, v in sorted(user_ns.items()): print(" %s (%s)" % (k, type(v))) import better_exchook better_exchook.debug_shell(user_ns, user_global_ns_new) if exit_afterwards: print("Debug shell exit. Exit now.") sys.exit(1)
def load(self): """ Loads the saved epoch data from file (self.filename). """ s = open(self.filename).read() self.epoch_data = eval(s, { "nan": float("nan"), "inf": float("inf") }, ObjAsDict(self))
def main(argv): print("DummySprintExec init", argv) args = ArgParser() args.parse(argv[1:]) if args.get("pymod-name"): SprintAPI = import_module(args.get("pymod-name")) else: import SprintExternInterface as SprintAPI inputDim = int(args.get("feature-dimension")) assert inputDim > 0 outputDim = int(args.get("trainer-output-dimension")) assert outputDim > 0 sprintConfig = args.get("pymod-config", "") targetMode = args.get("target-mode", "target-generic") SprintAPI.init(inputDim=inputDim, outputDim=outputDim, config=sprintConfig, targetMode=targetMode) if args.get("crnn-dataset"): dataset = eval(args.get("crnn-dataset"), {}, ObjAsDict(GeneratingDataset)) assert isinstance(dataset, Dataset) assert dataset.num_inputs == inputDim assert dataset.num_outputs == { "classes": [outputDim, 1], "data": [inputDim, 2] } dataset.init_seq_order(epoch=1) seq_idx = 0 while dataset.is_less_than_num_seqs(seq_idx): dataset.load_seqs(seq_idx, seq_idx + 1) features = dataset.get_data(seq_idx, "data") features = features.T # Sprint-like kwargs = {"features": features} if targetMode == "target-generic": if "orth" in dataset.get_target_list(): kwargs["orthography"] = dataset.get_targets( "orth", seq_idx) if "classes" in dataset.get_target_list(): kwargs["alignment"] = dataset.get_targets( "classes", seq_idx) print("DummySprintExec seq_idx %i feedInputAndTarget(**%r)" % (seq_idx, kwargs)) SprintAPI.feedInputAndTarget(**kwargs) else: raise NotImplementedError("targetMode = %s" % targetMode) seq_idx += 1 print("DummySprintExec exit") SprintAPI.exit()
def load(self): s = open(self.filename).read() self.epochData = eval(s, { "nan": float("nan"), "inf": float("inf") }, ObjAsDict(self))