mwptoolkit.utils.utils

mwptoolkit.utils.utils.clones(module, N)[source]

Produce N identical layers.

mwptoolkit.utils.utils.copy_list(l)[source]
mwptoolkit.utils.utils.get_model(model_name)[source]

Automatically select model class based on model name

Parameters

model_name (str) – model name

Returns

model class

Return type

Model

mwptoolkit.utils.utils.get_trainer(config)[source]

Automatically select trainer class based on task type and model name

Parameters

config (Config) –

Returns

trainer class

Return type

SupervisedTrainer

mwptoolkit.utils.utils.get_trainer_(task_type, model_name, sup_mode)[source]

Automatically select trainer class based on model type and model name

Parameters
  • model_type (TaskType) – model type

  • model_name (str) – model name

Returns

trainer class

Return type

Trainer

mwptoolkit.utils.utils.get_weakly_supervised(supervising_mode)[source]
mwptoolkit.utils.utils.init_seed(seed, reproducibility)[source]

init random seed for random functions in numpy, torch, cuda and cudnn

Parameters
  • seed (int) – random seed

  • reproducibility (bool) – Whether to require reproducibility

mwptoolkit.utils.utils.lists2dict(list1, list2)[source]

convert two lists to dict, elements of first list as keys, another’s as values.

mwptoolkit.utils.utils.read_ape200k_source(filename)[source]

specially used to read data of ape200k source file

mwptoolkit.utils.utils.read_json_data(filename)[source]

load data from a json file

mwptoolkit.utils.utils.read_math23k_source(filename)[source]

specially used to read data of math23k source file

mwptoolkit.utils.utils.str2float(v)[source]

convert string to float.

mwptoolkit.utils.utils.time_since(s)[source]

compute time

Parameters

s (float) – the amount of time in seconds.

Returns

formatting time.

Return type

(str)

mwptoolkit.utils.utils.write_json_data(data, filename)[source]

write data to a json file