How to use the saliency.base.GradientSaliency function in saliency

To help you get started, we’ve selected a few saliency examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PAIR-code / saliency / saliency / integrated_gradients.py View on Github external
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Utilities to compute an IntegratedGradients SaliencyMask."""

import tensorflow as tf
import numpy as np
from .base import GradientSaliency

class IntegratedGradients(GradientSaliency):
  """A SaliencyMask class that implements the integrated gradients method.

  https://arxiv.org/abs/1703.01365
  """

  def GetMask(self, x_value, feed_dict={}, x_baseline=None, x_steps=25):
    """Returns a integrated gradients mask.

    Args:
      x_value: input ndarray.
      x_baseline: Baseline value used in integration. Defaults to 0.
      x_steps: Number of integrated steps between baseline and x.
    """
    if x_baseline is None:
      x_baseline = np.zeros_like(x_value)
github PAIR-code / saliency / saliency / integrated_gradients.py View on Github external
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Utilities to compute an IntegratedGradients SaliencyMask."""

import tensorflow as tf
import numpy as np
from .base import GradientSaliency

class IntegratedGradients(GradientSaliency):
  """A SaliencyMask class that implements the integrated gradients method.

  https://arxiv.org/abs/1703.01365
  """

  def GetMask(self, x_value, feed_dict={}, x_baseline=None, x_steps=25):
    """Returns a integrated gradients mask.

    Args:
      x_value: input ndarray.
      x_baseline: Baseline value used in integration. Defaults to 0.
      x_steps: Number of integrated steps between baseline and x.
    """
    if x_baseline is None:
      x_baseline = np.zeros_like(x_value)
github PAIR-code / saliency / saliency / base.py View on Github external
def __init__(self, graph, session, y, x):
    super(GradientSaliency, self).__init__(graph, session, y, x)
    self.gradients_node = tf.gradients(y, x)[0]