whylogs.extras.image_metric#

Module Contents#

Classes#

ImageSubmetricSchema

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

ImageMetricConfig

ImageMetric

MultiMetric serves as a base class for custom metrics that consist

Functions#

get_pil_image_statistics(→ Dict)

Compute statistics data for a PIL Image

get_pil_exif_metadata(→ Dict)

Grab EXIF metadata from image

image_based_metadata(→ Dict[str, int])

get_pil_image_metadata(→ Dict)

Grab statistics data from a PIL ImageStats.Stat

init_image_schema(→ whylogs.core.schema.DatasetSchema)

Initialize a DatasetSchema for logging images. This can be passed into a logger or why.log.

log_image(→ whylogs.api.logger.result_set.ResultSet)

Attributes#

whylogs.extras.image_metric.logger#
whylogs.extras.image_metric.ImageType#
whylogs.extras.image_metric.DEFAULT_IMAGE_FEATURES: List[str] = []#
whylogs.extras.image_metric.get_pil_image_statistics(img: PIL.Image.Image, channels: List[str] = _IMAGE_HSV_CHANNELS, image_stats: List[str] = _STATS_PROPERTIES) Dict#

Compute statistics data for a PIL Image

Parameters
  • img (ImageType) – PIL Image

  • channels (List[str]) –

  • image_stats (List[str]) –

Returns

of metadata

Return type

Dict

whylogs.extras.image_metric.get_pil_exif_metadata(img: PIL.Image.Image) Dict#

Grab EXIF metadata from image

Parameters

img (ImageType) – PIL Image

Returns

of metadata

Return type

Dict

whylogs.extras.image_metric.image_based_metadata(img: PIL.Image.Image) Dict[str, int]#
Parameters

img (PIL.Image.Image) –

Return type

Dict[str, int]

whylogs.extras.image_metric.get_pil_image_metadata(img: PIL.Image.Image) Dict#

Grab statistics data from a PIL ImageStats.Stat

Parameters

img (ImageType) – PIL Image

Returns

of metadata

Return type

Dict

class whylogs.extras.image_metric.ImageSubmetricSchema#

Bases: whylogs.core.metrics.multimetric.SubmetricSchema

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

resolve(name: str, why_type: whylogs.core.datatypes.DataType, fi_disabled: bool = False) Dict[str, whylogs.core.metrics.metrics.Metric]#
Parameters
Return type

Dict[str, whylogs.core.metrics.metrics.Metric]

class whylogs.extras.image_metric.ImageMetricConfig#

Bases: whylogs.core.metrics.metrics.MetricConfig

allowed_exif_tags: Set[str]#
forbidden_exif_tags: Set[str]#
hll_lg_k: int#
kll_k: int#
fi_lg_max_k: int#
fi_disabled: bool#
track_unicode_ranges: bool#
large_kll_k: bool#
kll_k_large: int#
unicode_ranges: Dict[str, Tuple[int, int]]#
lower_case: bool#
normalize: bool#
max_frequent_item_size: int#
identity_column: Optional[str]#
class whylogs.extras.image_metric.ImageMetric(submetrics: Dict[str, Dict[str, whylogs.core.metrics.metrics.Metric]], allowed_exif_tags: Optional[Set[str]] = None, forbidden_exif_tags: Optional[Set[str]] = None, submetric_schema: Optional[whylogs.core.metrics.multimetric.SubmetricSchema] = None, type_mapper: Optional[whylogs.core.datatypes.TypeMapper] = None, fi_disabled: bool = False)#

Bases: whylogs.core.metrics.multimetric.MultiMetric

MultiMetric serves as a base class for custom metrics that consist of one or more metrics. It is handy when you need to do some processing of the logged values and track several metrics on the results. The sub-metrics must either be a StandardMetric, or tagged as a @custom_metric or registered via register_metric(). Note that MultiMetric is neither, so it cannot be nested.

Typically you will need to override namespace(); columnar_update(), calling it on the submetrics as needed; and the zero() method to return an appropriate “empty” instance of your metric. You will need to override from_protobuf() and merge() if your subclass __init__() method takes arguments different than MultiMetrtic’s. You can use the submetrics_from_protbuf() and merge_submetrics() helper methods to implement them. The MultiMetric class will handle the rest of the Metric interface. Don’t use / or : in the subclass’ namespace.

See UnicodeRangeMetric for an example.

Parameters
property namespace: str#
Return type

str

property exclude_from_serialization: bool#
Return type

bool

submetrics: Dict[str, Dict[str, whylogs.core.metrics.Metric]]#
merge(other: ImageMetric) ImageMetric#
Parameters

other (ImageMetric) –

Return type

ImageMetric

columnar_update(view: whylogs.core.preprocessing.PreprocessedColumn) whylogs.core.metrics.metrics.OperationResult#
Parameters

view (whylogs.core.preprocessing.PreprocessedColumn) –

Return type

whylogs.core.metrics.metrics.OperationResult

classmethod zero(config: Optional[whylogs.core.metrics.metrics.MetricConfig] = None) ImageMetric#
Parameters

config (Optional[whylogs.core.metrics.metrics.MetricConfig]) –

Return type

ImageMetric

merge_submetrics(other: MULTI_METRIC) Dict[str, Dict[str, whylogs.core.metrics.Metric]]#
Parameters

other (MULTI_METRIC) –

Return type

Dict[str, Dict[str, whylogs.core.metrics.Metric]]

to_protobuf() whylogs.core.proto.MetricMessage#
Return type

whylogs.core.proto.MetricMessage

get_component_paths() List[str]#
Return type

List[str]

to_summary_dict(cfg: Optional[whylogs.core.configs.SummaryConfig] = None) Dict[str, Any]#
Parameters

cfg (Optional[whylogs.core.configs.SummaryConfig]) –

Return type

Dict[str, Any]

classmethod submetrics_from_protobuf(msg: whylogs.core.proto.MetricMessage) Dict[str, Dict[str, whylogs.core.metrics.Metric]]#
Parameters

msg (whylogs.core.proto.MetricMessage) –

Return type

Dict[str, Dict[str, whylogs.core.metrics.Metric]]

classmethod from_protobuf(msg: whylogs.core.proto.MetricMessage) MULTI_METRIC#
Parameters

msg (whylogs.core.proto.MetricMessage) –

Return type

MULTI_METRIC

classmethod get_namespace(config: Optional[MetricConfig] = None) str#
Parameters

config (Optional[MetricConfig]) –

Return type

str

whylogs.extras.image_metric.init_image_schema(column_prefix: str = 'image') whylogs.core.schema.DatasetSchema#

Initialize a DatasetSchema for logging images. This can be passed into a logger or why.log.

Parameters
  • column_prefix (str) – The prefix that appears in the dataset profiles along with all of the

  • "image" (image features. If the prefix is) – image_data}).

  • why.log({image (then you'll log image with) – image_data}).

Return type

whylogs.core.schema.DatasetSchema

whylogs.extras.image_metric.log_image(images: Union[PIL.Image.Image, List[PIL.Image.Image], Dict[str, PIL.Image.Image]], default_column_prefix: str = 'image', schema: Optional[whylogs.core.schema.DatasetSchema] = None, trace_id: Optional[str] = None) whylogs.api.logger.result_set.ResultSet#
Parameters
Return type

whylogs.api.logger.result_set.ResultSet