niftynet.utilities.util_common module

traverse_nested(input_lists, types=(<type 'list'>, <type 'tuple'>))[source]

Flatten a nested list or tuple

list_depth_count(input_list)[source]

This function count the maximum depth of a nested list (recursively) This is used to check compatibility of users’ input and system API only to be used for list or tuple

average_multi_opt_gradients(multi_device_gradients)[source]

This function averages the gradients generated by each optimiser

average_gradients(multi_device_gradients)[source]

the input gradients are grouped by device, this function average the gradients of multiple devices

Parameters:multi_device_gradients – list of N gradients for N devices
Returns:
has_bad_inputs(input_args)[source]

Check if all input params have been properly set in the configuration file. :param input_args: :return:

print_save_input_parameters(args, txt_file=None)[source]
class MorphologyOps(binary_img, neigh)[source]

Bases: object

Class that performs the morphological operations needed to get notably connected component. To be used in the evaluation

border_map()[source]

Creates the border for a 3D image :return:

foreground_component()[source]
CachedFunction(func)[source]
CachedFunctionByID(func)[source]
class CacheFunctionOutput(func)[source]

Bases: object

this provides a decorator to cache function outputs to avoid repeating some heavy function computations

look_up_operations(type_str, supported)[source]

This function validates the type_str against the supported set.

if supported is a set, returns type_str if supported is a dict, return supported[type_str] else: raise an error possibly with a guess of the closest match.

Parameters:
  • type_str
  • supported
Returns:

damerau_levenshtein_distance(s1, s2)[source]

Calculates an edit distance, for typo detection. Code based on : https://en.wikipedia.org/wiki/Damerau–Levenshtein_distance

otsu_threshold(img, nbins=256)[source]

Implementation of otsu thresholding

Parameters:
  • img
  • nbins
Returns:

print_progress_bar(iteration, total, prefix='', suffix='', decimals=1, length=10, fill='=')[source]

Call in a loop to create terminal progress bar

Parameters:
  • iteration – current iteration (Int)
  • total – total iterations (Int)
  • prefix – prefix string (Str)
  • suffix – suffix string (Str)
  • decimals – number of decimals in percent complete (Int)
  • length – character length of bar (Int)
  • fill – bar fill character (Str)
set_cuda_device(cuda_devices)[source]
class ParserNamespace(**kwargs)[source]

Bases: object

Parser namespace for representing parsed parameters from config file

e.g.:

system_params = ParserNamespace(action='train')
action_str = system_params.action
update(**kwargs)[source]
device_string(n_devices=0, device_id=0, is_worker=True, is_training=True)[source]

assigning CPU/GPU based on user specifications

tf_config()[source]

tensorflow system configurations