API Python#

DVI Python bindings

dvi.getLibVersion() str#

Get library version

class dvi.DVI#
__init__() DVI#

Create an instance of DVI.

setup(self: dvi.DVI, image_size: numpy.ndarray[numpy.uint64]) dvi.DVI.Result#
Setup DVI instance, must be called before any other method.

Can also be used for changing images size of an already setup DVI Instance.

If this method fails, DVI instance reverts to creation state and must be setup again with success.

Parameters:

image_size ([int, int]) – Size (width, height) of images that DVI instance will process.

Returns:

Result of the operation. If OK, DVI instance is ready to be trained or loaded. Any other value indicates an error in usage.

train(self: dvi.DVI, good_train_images: List[numpy.ndarray[numpy.uint8]]) dvi.DVI.Result#

Train the model with nominal/good images provided. This can be called only after a successful DVI.setup(). The images must be all of the same size, in grayscale or BGR. Images size must coincide with image_size specified when calling DVI.setup().

Parameters:

good_train_images – list of nominal/good images.

Returns:

Result of the operation. If OK, DVI instance is ready to be used for test or saved. Any other value indicates an error in usage.

threshold_reference(self: dvi.DVI) Tuple[dvi.DVI.Result, float]#

Extract the computed reference threshold. This can be called only after a successful DVI.train() or DVI.load().

Returns:

Result of the operation and the threshold reference computed reference threshold computed on trained/loaded DVI Model (only if Result is OK).

test(self: dvi.DVI, test_images: List[numpy.ndarray[numpy.uint8]]) Tuple[dvi.DVI.Result, List[float], List[numpy.ndarray[numpy.float64]]]#

Test the model on images, providing scores and maps in output.

This method can be called only after a successful DVI.train() or DVI.load(). The images must be all of the same size, in grayscale or BGR. Images size must coincide with image_size specified when calling DVI.setup().

Parameters:

test_images – list of images to be tested.

Returns:

Result of the operation, list of scores and list of maps. If OK, the lists are filled with the scores and maps of the tested images. Any other value indicates an error in usage. Scores and maps be compared with a threshold afterwards (specified by user or obtained by DVI.threshold_reference()) for assigning a nominal/anomalous label to image.

save(self: dvi.DVI, model_path: str | pathlib.Path) dvi.DVI.Result#

Save the trained model to a file at the provided path.

This method can be called only after a successful DVI.train() or DVI.load().

Make sure that the path is writable by the process.

Parameters:

model_path – path where to save the model.

Returns:

Result of the operation. If OK, the model is saved at the provided path. Any other value indicates an error in usage.

load(self: dvi.DVI, model_path: str | pathlib.Path) dvi.DVI.Result#

Load a trained model from a file.

This method can be called only after a successful DVI.setup(). Make sure that the path is a readable file for the process.

Parameters:

model_path – path where to load the model from (previously saved with DVI.save()).

Returns:

Result of the operation. If OK, the model is loaded from the provided path. Any other value indicates an error in usage.

class Result#
OK (0) Success#
ERROR_GENERIC (1) Generic internal error. Please get in touch with DVI team for troubleshooting#
ERROR_THREHSOLD_REFERENCE_NOT_AVAILABLE (2) The reference threshold could not be extracted. Check that DVI.train() or DVI.load() methods has been called succesfully#
ERROR_NOT_SETUP_YET (3) DVI.setup() must be called before calling the method that returned this Result#
ERROR_NOT_TRAINED_OR_LOADED_YET (5) DVI must be trained or loaded before calling the method that returned this Result. Call DVI.train() or DVI.load() with appropriate arguments#
ERROR_ALREADY_TRAINED_OR_LOADED (6) DVI already trained or loaded, can't call twice the method that returned this Result#
ERROR_NO_NOMINAL_IMAGE_PROVIDED (7) No image has been provided when calling DVI.train()#
ERROR_EMPTY_NOMINAL_IMAGE_PROVIDED (8) An image provided to DVI.train() is empty#
ERROR_INVALID_IMAGE_SIZE (15) An image provided to DVI.train() or DVI.test() has a different size than the one provided during DVI.setup()#
ERROR_WRONG_SETUP_SIZE_FOR_MULTIPLE_MODELS (16) DVI.setup() is launched with different image size from already setup models#
ERROR_INVALID_IMAGES (9) At least one of the provided images is not valid.#
ERROR_INVALID_PRIVATES (10) Provided privates string is invalid, please check for correctness or contact DVI team#
ERROR_CANNOT_READ_MODEL_FILE (11) Model file cannot be found at provided path#
ERROR_CANNOT_PARSE_MODEL_FILE (12) Model file cannot be loaded, please check for correctness or contact DVI team#
ERROR_ULA_NOT_ACCEPTED (13) U.L.A. (User License Agreeement) has not been accepted yet. Run the program dvi_accept_ula#
ERROR_ULA_INVALID (14) An error occured while checking U.L.A. acceptance. Run the program dvi_accept_ula or contact DVI team#
ERROR_INTERNAL_1 .. ERROR_INTERNAL_57: Internal errors. Please get in touch with DVI team for troubleshooting#