vision_unlearning.benchmarks.I_care.utils

Utility helpers for the I-CARE benchmark.

  • Image encoding/decoding (base64 PNG)

  • SHAP Explanation serialization (requires shap package — optional dep)

  • Error classes used across result templates

Note: shap is imported lazily inside functions to avoid forcing all users to install it. It is only needed for the SHAP-related result templates.

Exceptions

InvalidAttributeTypeError

Inappropriate argument value (of correct type).

InsufficientSamplesError

Inappropriate argument value (of correct type).

Functions

_encode_image_file(→ str)

Downsample / reduce resolution to limit size before encoding

_decode_image(→ io.BytesIO)

explanation_to_dict(→ Dict[str, Any])

Serialize a shap.Explanation to a plain dict (JSON-serializable).

dict_to_explanation(→ Any)

Deserialize a plain dict back to a shap.Explanation.

Module Contents

vision_unlearning.benchmarks.I_care.utils._encode_image_file(img_path: str, max_dim: int = 1024) str

Downsample / reduce resolution to limit size before encoding

vision_unlearning.benchmarks.I_care.utils._decode_image(image_data: str) io.BytesIO
vision_unlearning.benchmarks.I_care.utils.explanation_to_dict(expl: Any) Dict[str, Any]

Serialize a shap.Explanation to a plain dict (JSON-serializable).

vision_unlearning.benchmarks.I_care.utils.dict_to_explanation(d: Dict[str, Any]) Any

Deserialize a plain dict back to a shap.Explanation.

Requires ‘shap’ package (optional dependency — install with pip install shap or pip install vision-unlearning[testbed]).

exception vision_unlearning.benchmarks.I_care.utils.InvalidAttributeTypeError

Bases: ValueError

Inappropriate argument value (of correct type).

exception vision_unlearning.benchmarks.I_care.utils.InsufficientSamplesError

Bases: ValueError

Inappropriate argument value (of correct type).