Module delta.subcommands.classify

Classify input images given a model.

Functions

def ae_convert(data)
def classify_image(model, image, label, path, net_name, options, shapes=None, persistent_metrics=None)

Classify an image and return the confusion matrix and metrics if labels were provided

def get_metrics()

Returns a list of specified metrics, wrapping up losses as metrics

def get_roi_containing_shapes(shapes) ‑> Rectangle

Return a Rectangle containing all the shapes or None if none were passed in

def get_wkt_path(image_path, wkt_folder=None)

Return the path to where the WKT file for an image should be

def load_shapes_matching_tag(wkt_path, tag)

Returns a list of all the shapes defined for this tag in the WKT file. If tag is None, return untagged regions

def load_wkt_shapes(wkt_path, image_path, region_name)

Loads shapes (in image coordinates) from an image's WKT file

def main(options)
def print_classes(output_file, cm, metrics, comment)
def save_confusion(cm, class_labels, filename)
def shapes_to_pixel_coordinates(shapes, image_path)

Convert any shapes not in pixel coordinates to pixel coordinates. Always returns a list of Polygon objects, even if the input list contains MultiPolygon objects.

Classes

class LossToMetricWrapper (loss_object)

Wrap a Loss object to make it behave like a Metric object

Expand source code
class LossToMetricWrapper(tensorflow.keras.metrics.Metric):
    """Wrap a Loss object to make it behave like a Metric object"""
    def __init__(self, loss_object):
        super().__init__(name=loss_object.name)
        self._loss_object = loss_object
        self._moving_average = 0.0
        self._total_count = 0

    def update_state(self, y_true, y_pred, sample_weight=None): #pylint: disable=unused-argument, arguments-differ
        this_loss = self._loss_object.call(y_true, y_pred)
        if isinstance(this_loss, tf.Tensor):
            this_loss = this_loss.numpy()
        elif not isinstance(this_loss, np.ndarray):
            this_loss = np.ndarray(this_loss)
        self._total_count += y_true.size
        self._moving_average += (this_loss.mean() - self._moving_average) * (y_true.size / self._total_count)

    def result(self):
        return self._moving_average

Ancestors

  • keras.src.metrics.base_metric.Metric
  • keras.src.engine.base_layer.Layer
  • tensorflow.python.module.module.Module
  • tensorflow.python.trackable.autotrackable.AutoTrackable
  • tensorflow.python.trackable.base.Trackable
  • keras.src.utils.version_utils.LayerVersionSelector

Methods

def result(self)

Computes and returns the scalar metric value tensor or a dict of scalars.

Result computation is an idempotent operation that simply calculates the metric value using the state variables.

Returns

A scalar tensor, or a dictionary of scalar tensors.

def update_state(self, y_true, y_pred, sample_weight=None)

Accumulates statistics for the metric.

Note: This function is executed as a graph function in graph mode. This means: a) Operations on the same resource are executed in textual order. This should make it easier to do things like add the updated value of a variable to another, for example. b) You don't need to worry about collecting the update ops to execute. All update ops added to the graph by this function will be executed. As a result, code should generally work the same way with graph or eager execution.

Args

*args:
**kwargs
A mini-batch of inputs to the Metric.