neural_compressor.tensorflow.utils.utility

The utility functions and classes for Tensorflow.

Classes

CpuInfo

Get CPU Info.

CaptureOutputToFile

Not displayed in API Docs.

TFSlimNetsFactory

TF-Slim nets factory.

Functions

version1_lt_version2(version1, version2)

Check whether version1 is less than version2.

version1_gt_version2(version1, version2)

Check whether version1 is greater than version2.

version1_eq_version2(version1, version2)

Check whether version1 is equal to version2.

version1_gte_version2(version1, version2)

Check whether version1 is greater than version2 or is equal to it.

version1_lte_version2(version1, version2)

Check whether version1 is less than version2 or is equal to it.

register_algo(name)

Decorator function to register algorithms in the algos_mapping dictionary.

deep_get(dictionary, keys[, default])

Get the dot key's item in nested dict.

itex_installed()

Check if the Intel® Extension for TensorFlow has been installed.

dump_elapsed_time([customized_msg])

Get the elapsed time for decorated functions.

combine_histogram(old_hist, arr)

Collect layer histogram for arr and combine it with old histogram.

get_all_fp32_data(data)

Get all the fp32 data.

get_tensor_histogram(tensor_data[, bins])

Get the histogram of the tensor data.

singleton(cls)

Not displayed in API Docs.

disable_random([seed])

A Decorator to disable tf random seed.

valid_keras_format(model)

Check if the input model is Sequential or Functional model.

Module Contents

neural_compressor.tensorflow.utils.utility.version1_lt_version2(version1, version2)[source]

Check whether version1 is less than version2.

neural_compressor.tensorflow.utils.utility.version1_gt_version2(version1, version2)[source]

Check whether version1 is greater than version2.

neural_compressor.tensorflow.utils.utility.version1_eq_version2(version1, version2)[source]

Check whether version1 is equal to version2.

neural_compressor.tensorflow.utils.utility.version1_gte_version2(version1, version2)[source]

Check whether version1 is greater than version2 or is equal to it.

neural_compressor.tensorflow.utils.utility.version1_lte_version2(version1, version2)[source]

Check whether version1 is less than version2 or is equal to it.

neural_compressor.tensorflow.utils.utility.register_algo(name)[source]

Decorator function to register algorithms in the algos_mapping dictionary.

Usage example:

@register_algo(name=example_algo) def example_algo(model: tf.keras.Model, quant_config: StaticQuantConfig) -> tf.keras.Model:

Parameters:

name (str) – The name under which the algorithm function will be registered.

Returns:

The decorator function to be used with algorithm functions.

Return type:

decorator

neural_compressor.tensorflow.utils.utility.deep_get(dictionary, keys, default=None)[source]

Get the dot key’s item in nested dict.

Usage example:

person = {‘person’:{‘name’:{‘first’:’John’}}} deep_get(person, “person.name.first”) will output ‘John’.

Parameters:
  • dictionary (dict) – The dict object to get keys

  • keys (dict) – The deep keys

  • default (object) – The return item if key not exists

Returns:

the item of the deep dot keys

Return type:

item

neural_compressor.tensorflow.utils.utility.itex_installed()[source]

Check if the Intel® Extension for TensorFlow has been installed.

neural_compressor.tensorflow.utils.utility.dump_elapsed_time(customized_msg='')[source]

Get the elapsed time for decorated functions.

Parameters:

customized_msg (string, optional) – The parameter passed to decorator. Defaults to None.

neural_compressor.tensorflow.utils.utility.combine_histogram(old_hist, arr)[source]

Collect layer histogram for arr and combine it with old histogram.

neural_compressor.tensorflow.utils.utility.get_all_fp32_data(data)[source]

Get all the fp32 data.

neural_compressor.tensorflow.utils.utility.get_tensor_histogram(tensor_data, bins=2048)[source]

Get the histogram of the tensor data.

neural_compressor.tensorflow.utils.utility.singleton(cls)[source]

Not displayed in API Docs.

Singleton decorator.

neural_compressor.tensorflow.utils.utility.disable_random(seed=1)[source]

A Decorator to disable tf random seed.

neural_compressor.tensorflow.utils.utility.valid_keras_format(model)[source]

Check if the input model is Sequential or Functional model.

class neural_compressor.tensorflow.utils.utility.CpuInfo[source]

Get CPU Info.

class neural_compressor.tensorflow.utils.utility.CaptureOutputToFile(tmp_file_path, stream=sys.stderr)[source]

Not displayed in API Docs.

Capture the output to file.

class neural_compressor.tensorflow.utils.utility.TFSlimNetsFactory[source]

TF-Slim nets factory.