Skip to content

Commit

Permalink
Add sigmoid to proba activations. Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
teabolt committed Jul 1, 2019
1 parent eb93d51 commit a5cab1a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
6 changes: 3 additions & 3 deletions docs/source/libraries/keras.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ explain_prediction
Currently ELI5 supports :func:`eli5.explain_prediction` for Keras image classifiers.

:func:`eli5.explain_prediction` explains image classifications through `Grad-CAM <https://arxiv.org/pdf/1610.02391.pdf>`_.
The :class:`eli5.base.Explanation` object returned has an ``.image`` attribute and a ``.heatmap`` attribute.
``image`` represents the image that is inputted into the model.
``heatmap`` is a grayscale "localization map", roughly indicating regions of importance in the image for the predicted class.
The returned :class:`eli5.base.Explanation` object has some important properties:
* ``image`` represents the image that is inputted into the model.
* ``heatmap`` is a grayscale "localization map", roughly indicating regions of importance in the image for the predicted class.


Important arguments for ``Model`` and ``Sequential``:
Expand Down
24 changes: 14 additions & 10 deletions eli5/keras/explain_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ def explain_prediction_keras(estimator, # type: Model
Returns
-------
expl : Explanation
A :class:`eli5.base.Explanation` object
with the ``image`` attribute set and a
``heatmap`` attribute inside ``targets``.
``image`` is a Pillow image with mode RGBA.
``heatmap`` is a rank 2 numpy array with the localization map values.
expl : eli5.base.Explanation
An ``Explanation`` object with the following attributes set
(some inside ``targets``):
* ``image`` a Pillow image with mode RGBA.
* ``heatmap`` a rank 2 numpy array with the localization map values.
* ``target`` ID of target class.
* ``proba`` output for target class for ``softmax`` or ``sigmoid`` outputs.
* ``score`` output for target class for other activations.
"""
_validate_doc(estimator, doc)
activation_layer = _get_activation_layer(estimator, layer)
Expand Down Expand Up @@ -243,8 +243,12 @@ def _outputs_proba(estimator):
output_layer = estimator.get_layer(index=-1)
# we check if the network's output is put through softmax
# we assume that only softmax can output 'probabilities'

try:
return output_layer.activation is keras.activations.softmax
actv = output_layer.activation
except AttributeError:
# output layer does not support activation function
return False
return False
else:
return (actv is keras.activations.softmax or
actv is keras.activations.sigmoid)

0 comments on commit a5cab1a

Please sign in to comment.