aigarmic.model

Implementation of Model classes

Classes

Model

Helper class that provides a standard way to create an ABC using

KerasModel

Helper class that provides a standard way to create an ABC using

SoftmaxModel

SoftmaxModel is a one-stop model when more than one growth category is present, e.g.:

BinaryModel

Helper class that provides a standard way to create an ABC using

BinaryNestedModel

Helper class that provides a standard way to create an ABC using

Functions

convert_cv2_to_keras(→ numpy.ndarray)

Convert a cv2 image to a keras image

Module Contents

aigarmic.model.convert_cv2_to_keras(image, size_x=160, size_y=160) numpy.ndarray[source]

Convert a cv2 image to a keras image

Parameters:
  • image – Image loaded using cv2.imread

  • size_x – Width to resize image to (pixels)

  • size_y – Height to resize image to (pixels)

Returns:

Image as a numpy array

class aigarmic.model.Model(key: list[str] | None)[source]

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

get_key() list[str][source]

Return key to convert model output to human-readable label :return:

abstract predict(image) dict[source]
class aigarmic.model.KerasModel(path: str, trained_x: int, trained_y: int, key: list[str] | None)[source]

Bases: Model

Helper class that provides a standard way to create an ABC using inheritance.

load_model(path: str) None[source]

Load a keras model from file

Parameters:

path – path to saved model

abstract predict(image: numpy.ndarray) dict[source]
class aigarmic.model.SoftmaxModel(path: str, trained_x: int, trained_y: int, key: list[str] | None)[source]

Bases: KerasModel

SoftmaxModel is a one-stop model when more than one growth category is present, e.g.: [‘No growth’, ‘Poor growth’, ‘Good growth’]

predict(image: numpy.ndarray) dict[source]

Predict growth category from image

Parameters:

image – loaded using cv2.imread

Returns:

dictionary with keys ‘prediction’, ‘score’, ‘growth_code’, ‘growth’, ‘accuracy’

class aigarmic.model.BinaryModel(path: str, trained_x: int, trained_y: int, key: list[str] | None, threshold: float = 0.5)[source]

Bases: KerasModel

Helper class that provides a standard way to create an ABC using inheritance.

predict(image: numpy.ndarray) dict[source]

Predict growth category from image

Parameters:

image – image loaded using cv2.imread

Returns:

dictionary with keys ‘prediction’, ‘score’, ‘growth_code’, ‘growth’, ‘accuracy’

class aigarmic.model.BinaryNestedModel(first_line_model: BinaryModel, second_line_model: BinaryModel, first_model_accuracy_acceptance: float = 0.9, suppress_first_model_accuracy_check: bool = False)[source]

Bases: Model

Helper class that provides a standard way to create an ABC using inheritance.

predict(image: numpy.ndarray) dict[source]

Predict colony growth from image

Parameters:

image – image loaded using cv2.imread

Returns:

dictionary with keys ‘prediction’, ‘score’, ‘growth_code’, ‘growth’, ‘accuracy’