{"id":23162,"library":"saliency","title":"Saliency","description":"Framework-agnostic library for computing saliency maps (e.g., integrated gradients, SmoothGrad, XRAI) for deep learning models. Current version: 0.2.1. Release cadence is low, with updates driven by research contributions.","status":"active","version":"0.2.1","language":"python","source_language":"en","source_url":"https://github.com/pair-code/saliency","tags":["saliency","explainability","integration-gradients","smoothgrad","xrai"],"install":[{"cmd":"pip install saliency","lang":"bash","label":"Standard install"}],"dependencies":[{"reason":"Core dependency for array operations.","package":"numpy","optional":false},{"reason":"Image loading and visualization.","package":"pillow","optional":false},{"reason":"Default backend for model integration.","package":"tensorflow","optional":true},{"reason":"Alternative backend for PyTorch models.","package":"torch","optional":true}],"imports":[{"note":"The top-level module does not expose submodules directly; use explicit import.","wrong":"import saliency","symbol":"core","correct":"from saliency import core"},{"note":"Classes are in submodules like core, not directly in saliency.","wrong":"from saliency import IntegratedGradients","symbol":"IntegratedGradients","correct":"from saliency.core import IntegratedGradients"},{"note":"Same as above; use correct submodule path.","wrong":"from saliency import SmoothGrad","symbol":"SmoothGrad","correct":"from saliency.core import SmoothGrad"},{"note":"XRAI is in its own submodule 'xrai', not in core.","wrong":"","symbol":"XRAI","correct":"from saliency.xrai import XRAI"},{"note":"Visualization utilities are in core.","wrong":"from saliency import visualize","symbol":"visualize","correct":"from saliency.core import visualize"}],"quickstart":{"code":"import tensorflow as tf\nfrom saliency.core import IntegratedGradients, visualize\n\n# Build a simple model\nmodel = tf.keras.Sequential([\n    tf.keras.layers.Dense(10, activation='relu', input_shape=(4,)),\n    tf.keras.layers.Dense(1, activation='sigmoid')\n])\n\n# Dummy input and baseline\nx_input = tf.constant([[1.0, 2.0, 3.0, 4.0]])\nbaseline = tf.zeros_like(x_input)\n\n# Call model wrapper\ndef model_fn(x):\n    return model(x)\n\n# Compute integrated gradients\nig = IntegratedGradients()\nattributions = ig.GetMask(x_input, model_fn, baseline, x_steps=25)\nprint(attributions)","lang":"python","description":"Compute integrated gradients on a simple Keras model."},"warnings":[{"fix":"Update imports: from saliency.core import IntegratedGradients (and others). Also update method calls (e.g., GetMask instead of GetMask).","message":"In version 0.2.0, the API was overhauled: previous methods like `saliency.IntegratedGradients` moved to `saliency.core`. Code using old import paths will break.","severity":"breaking","affected_versions":"<0.2.0"},{"fix":"Monitor repository for updated API; aim to use any newer method names once released.","message":"The method `GetMask` in IntegratedGradients may be deprecated in future in favor of `compute_saliency` or similar naming. Check CHANGELOG.","severity":"deprecated","affected_versions":">=0.2.0"},{"fix":"Ensure you pass the full attributions tensor (including negative values) to XRAI, not a rectified version.","message":"XRAI method requires both positive and negative attributions; using only positive attributions will produce incorrect masks.","severity":"gotcha","affected_versions":"all"},{"fix":"Always use a model that returns logits, or modify the model function to return logits before activation.","message":"The library expects models to output logits (pre-softmax) for gradient calculations. Using softmax outputs may lead to vanishing gradients.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Upgrade to latest: pip install --upgrade saliency","cause":"Older version installed (<0.2.0) where core module didn't exist.","error":"ModuleNotFoundError: No module named 'saliency.core'"},{"fix":"Use: from saliency.core import IntegratedGradients","cause":"Importing directly from top-level saliency instead of submodule.","error":"AttributeError: module 'saliency' has no attribute 'IntegratedGradients'"},{"fix":"Provide x_steps explicitly, e.g., GetMask(..., x_steps=25)","cause":"x_steps parameter is required since version 0.2.0 (old default removed).","error":"TypeError: GetMask() missing 1 required positional argument: 'x_steps'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}