utils

Utility functions that can be used in multiple scripts.

hwrt.utils.choose_raw_dataset(currently='')

Let the user choose a raw dataset. Return the absolute path.

hwrt.utils.classify_single_recording(raw_data_json, model_folder, verbose=False)

Get the classification as a list of tuples. The first value is the LaTeX code, the second value is the probability.

hwrt.utils.create_adjusted_model_for_percentages(model_src, model_use)

Replace logreg layer by sigmoid to get probabilities.

hwrt.utils.create_hdf5(output_filename, feature_count, data)

Create a HDF5 feature files.

Parameters:

output_filename : string

name of the HDF5 file that will be created

feature_count : int

dimension of all features combined

data : list of tuples

list of (x, y) tuples, where x is the feature vector of dimension feature_count and y is a label.

hwrt.utils.create_project_configuration(filename)

Create a project configuration file which contains a configuration that might make sense.

hwrt.utils.create_run_logfile(folder)

Create a ‘run.log’ within folder. This file contains the time of the latest successful run.

hwrt.utils.default_model()

Get a path for a default value for the model. Start searching in the current directory.

hwrt.utils.evaluate_model(recording, model_folder, verbose=False)

Evaluate model for a single recording.

hwrt.utils.evaluate_model_single_recording(model_file, recording)

Evaluate a model for a single recording.

Parameters:

model_file : string

Model file (.tar)

recording :

The handwritten recording.

hwrt.utils.evaluate_model_single_recording_multisymbol(model_file, recording)

Evaluate a model for a single recording where possibly multiple symbols are.

Parameters:

model_file : string

Model file (.tar)

recording :

The handwritten recording.

hwrt.utils.evaluate_model_single_recording_preloaded(preprocessing_queue, feature_list, model, output_semantics, recording, recording_id=None)

Evaluate a model for a single recording, after everything has been loaded.

Parameters:

preprocessing_queue : list

List of all preprocessing objects.

feature_list : list

List of all feature objects.

model : dict

Neural network model.

output_semantics : list

List that defines what an output means.

recording : string in JSON format

The handwritten recording in JSON format.

hwrt.utils.evaluate_model_single_recording_preloaded_multisymbol(preprocessing_queue, feature_list, model, output_semantics, recording)

Evaluate a model for a single recording, after everything has been loaded. Multiple symbols are recognized.

Parameters:

preprocessing_queue : list

List of all preprocessing objects.

feature_list : list

List of all feature objects.

model : dict

Neural network model.

output_semantics :

List that defines what an output means.

recording :

The handwritten recording in JSON format.

hwrt.utils.get_class(name, config_key, module)

Get the class by its name as a string.

hwrt.utils.get_database_config_file()

Get the absolute path to the database configuration file.

hwrt.utils.get_database_configuration()

Get database configuration as dictionary.

hwrt.utils.get_index2data(model_description)

Get a dictionary that maps indices to a list of (1) the id in the hwrt symbol database (2) the latex command (3) the unicode code point (4) a font family and (5) a font style.

Parameters:

model_description : string

A model description file that points to a feature folder where an index2formula_id.csv has to be.

Returns:

dictionary

that maps indices to lists of data

Notes

This command need a database connection.

hwrt.utils.get_index2latex(model_description)

Get a dictionary that maps indices to LaTeX commands.

Parameters:

model_description : string

A model description file that points to a feature folder where an index2formula_id.csv has to be.

Returns:

dictionary :

Maps indices to LaTeX commands

hwrt.utils.get_latest_folder(folder)

Get the absolute path of a subfolder that comes last with natural sorting in the given folder.

hwrt.utils.get_latest_in_folder(folder, ending='', default='')

Get the file that comes last with natural sorting in folder and has file ending ‘ending’.

hwrt.utils.get_latest_model(model_folder, basename)

Get the latest model (determined by the name of the model in natural sorted order) which begins with basename.

hwrt.utils.get_latest_successful_run(folder)

Get the latest successful run timestamp.

hwrt.utils.get_latest_working_model(model_folder)

Get the latest working model. Delete all others that get touched.

hwrt.utils.get_nntoolkit()

Get the project root folder as a string.

hwrt.utils.get_objectlist(description, config_key, module)

Take a description and return a list of classes.

Parameters:

description : list of dictionaries

Each dictionary has only one entry. The key is the name of a class. The value of that entry is a list of dictionaries again. Those dictionaries are paramters.

Returns:

List of objects.

hwrt.utils.get_online_symbol_data(database_id)

Get from the server.

hwrt.utils.get_possible_splits(n)
Parameters:

n : int

n strokes were make

hwrt.utils.get_project_configuration()

Get project configuration as dictionary.

hwrt.utils.get_project_root()

Get the project root folder as a string.

hwrt.utils.get_readable_time(t)

Format the time to a readable format.

Parameters:

t : int

Time in ms

Returns:

string

The time splitted to highest used time (minutes, hours, ...)

hwrt.utils.get_recognizer_folders(model_folder)

Get a list of folders [preprocessed, feature-files, model].

hwrt.utils.get_template_folder()

Get path to the folder where th HTML templates are.

hwrt.utils.input_int_default(question='', default=0)

A function that works for both, Python 2.x and Python 3.x. It asks the user for input and returns it as a string.

hwrt.utils.input_string(question='')

A function that works for both, Python 2.x and Python 3.x. It asks the user for input and returns it as a string.

hwrt.utils.is_valid_file(parser, arg)

Check if arg is a valid file that already exists on the file system.

hwrt.utils.is_valid_folder(parser, arg)

Check if arg is a valid file that already exists on the file system.

hwrt.utils.less_than(l, n)

Get number of symbols in list l which have a value less than n.

Parameters:

l : list of numbers

n : int

Returns:

float :

Number of elements of the list l which are strictly less than n.

hwrt.utils.load_model(model_file)

Load a model by its file. This includes the model itself, but also the preprocessing queue, the feature list and the output semantics.

hwrt.utils.print_status(total, current, start_time=None)

Show how much work was done / how much work is remaining.

Parameters:

total : float

The total amount of work

current : float

The work that has been done so far

start_time : int

The start time in seconds since 1970 to estimate the remaining time.

hwrt.utils.query_yes_no(question, default='yes')

Ask a yes/no question via raw_input() and return their answer.

“question” is a string that is presented to the user. “default” is the presumed answer if the user just hits <Enter>.

It must be “yes” (the default), “no” or None (meaning an answer is required of the user).

The “answer” return value is one of “yes” or “no”.

hwrt.utils.segment_by_split(split, recording)
Parameters:

split : String of 0s and 1s

For example “010”.

recording : list

A recording of handwritten text.

hwrt.utils.sizeof_fmt(num)

Takes the a filesize in bytes and returns a nicely formatted string.

Previous topic

segmentation

This Page