blocks.utils¶
Submodules¶
Functions¶
resize_and_pad(): Resize and pad (with zeros) the given image to the target width and height.create_clean_dir(): Create a clean directory with the given name in CWD.raise_moved(): RaiseNameErrorwith the function/feature moved/renamed info message.base64_to_cv2(): Transform base64-encoded string to OpenCV image.bytes_to_base64(): Transform bytes to base64-encoded string.cv2_to_base64(): Transform OpenCV image to base64-encoded string.decode_ctc_prediction(): Decode raw CTC prediction to the actual output assuming that the last prediction bitdecode_ctc_prediction_with_eos(): Same asdecode_ctc_prediction()but cut the prediction (and indices) at <EOS> character assuming thatdecode_rpn_predictions(): Decode the given RPN predictions to a list of regions.classmaker(): Undocumented.try_import(): Try to import and return the specified class. If it fails return an empty class instead.get_balancing_weights(): Compute weights balancing zeros and ones in the given masks tensor.
-
blocks.utils.resize_and_pad(image, target_width, target_height, upscale=True)[source]¶ Resize and pad (with zeros) the given image to the target width and height.
-
blocks.utils.create_clean_dir(dir_name)[source]¶ Create a clean directory with the given name in CWD.
-
blocks.utils.raise_moved(name, new_name)[source]¶ Raise
NameErrorwith the function/feature moved/renamed info message.Tip
Use this function when moving/renaming function/features. Our projects may rely on them!
-
blocks.utils.base64_to_cv2(string_base64, imread_flag=1)[source]¶ Transform base64-encoded string to OpenCV image.
- Return type
ndarray
-
blocks.utils.cv2_to_base64(image, extension='.png')[source]¶ Transform OpenCV image to base64-encoded string.
- Return type
-
blocks.utils.decode_ctc_prediction(ctc_prediction)[source]¶ Decode raw CTC prediction to the actual output assuming that the last prediction bit is reserved for the empty character.
-
blocks.utils.decode_ctc_prediction_with_eos(ctc_prediction)[source]¶ Same as
decode_ctc_prediction()but cut the prediction (and indices) at <EOS> character assuming that <EOS> = dim-2.- Parameters
ctc_prediction – 2d array of time x probabilities
- Returns
a tuple of (decoded predictions, indices of emitted characters)
-
blocks.utils.decode_rpn_predictions(dataset, classifier_probabilities, regression_predictions, non_maximum_suppression=0.3, min_probability=None, top_k=None)[source]¶ Decode the given RPN predictions to a list of regions.
- Optionally:
use non maximum suppression
filter out regions with low probability
output only top k regions
- Parameters
dataset (
RPNDataset) – RPN dataset which created the anchorsclassifier_probabilities (
ndarray) – predicted classifier probabilities (in 0-1 interval)regression_predictions (
ndarray) – predicted diffs regression valuesnon_maximum_suppression (
Optional[float]) – if specified, use nms with the given thresholdmin_probability (
Optional[float]) – if specified, filter out regions with probability lower than the specified thresholdtop_k (
Optional[int]) – if specified, output only top k regions
- Return type
- Returns
list of decoded regions
-
blocks.utils.try_import(class_fqn)[source]¶ Try to import and return the specified class. If it fails return an empty class instead.
example usage with hipipe dataset¶import blocks as bl class OdoCapDataset(bl.utils.try_import('my_module.Dataset'), bl.datasets.RectangleRPNDataset, metaclass=bl.utils.classmaker()):
-
blocks.utils.get_balancing_weights(masks, correction=0.001)[source]¶ Compute weights balancing zeros and ones in the given masks tensor.
Warning
The masks tensor must be binary - i.e., contain only ones and zeros!
- Parameters
masks (
Tensor) – zero/one masks to be balancedcorrection (
float) – correction parameter to avoid divergence of weights
- Return type
Tensor- Returns
weights balancing the given mask (having the same shape)
Classes¶
DemoOutputBuilder: Building demo outputs to be displayed in Iterait demo web application.
-
class
blocks.utils.DemoOutputBuilder[source]¶ Bases:
objectBuilding demo outputs to be displayed in Iterait demo web application.
example usage¶output = blocks.utils.DemoOutputBuilder().add_image(im).add_table(['col1', 'col2'], [['lorem ipsum', im2]]).output # output ~ demo-compatible json-serializable dict

-
add_image_transformation(original, transformed, extension='.jpg')[source]¶ Add image comparison block to the output.
- Return type
-