DLR Python API

DLR: Compact Runtime for Machine Learning Models

class dlr.DLRModel(**kwargs)
get_input(name, shape=None)

Get the current value of an input.

Parameters
  • name (str) – The name of an input

  • shape (np.array (optional)) – If given, use as the shape of the returned array. Otherwise, the shape of the returned array will be inferred from the last call to set_input().

get_input_dtype(index)

Get the type of the input at the given index.

Parameters

index (int) – Index of the input

Returns

type

Return type

str

get_input_dtypes()

Get datatype of all inputs.

Returns

dtypes

Return type

list of str

get_input_name(index)

Get the name of the input at the given index.

Parameters

index (int) – Index of the input

Returns

name

Return type

str

get_input_names()

Get all input names

Returns

out

Return type

list of str

get_output_dtype(index)

Get the type of the output at the given index.

Parameters

index (int) – Index of the input

Returns

type

Return type

str

get_output_dtypes()

Get datatype of all outputs.

Returns

dtypes

Return type

list of str

get_output_name(index)

Get the name of the output at the given index. Only valid when the model has a metadata file.

Parameters

index (int) – Index of the input

Returns

name

Return type

str

get_output_names()

Get all output names. Only valid when the model has a metadata file.

Returns

names

Return type

list of str

get_version()

Get version of loaded DLR library.

Returns

version

Return type

str “{major}.{minor}.{patch}”

has_metadata()

Whether the model has a metadata file which provides additional information such as output names.

Returns

has_metadata

Return type

bool

run(input_values)

Run inference with given input(s)

Parameters

input_values (a single numpy.ndarray or a dictionary) –

For decision tree models, provide a single numpy.ndarray to indicate a single input, as decision trees always accept only one input.

For deep learning models, provide a dictionary where keys are input names (of type str) and values are input tensors (of type numpy.ndarray). Deep learning models allow more than one input, so each input must have a unique name.

Returns

out – Prediction result

Return type

numpy.ndarray