Skip to content

updates Keras and tensorflow version [MNT] #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions eli5/keras/explain_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def explain_prediction_keras(model, # type: Model

The tensor must be of suitable shape for the ``model``.

Check ``model.input_shape`` to confirm the required dimensions of the input tensor.
Check ``model.input.shape`` to confirm the required dimensions of the input tensor.


:raises TypeError: if ``doc`` is not a numpy array.
Expand Down Expand Up @@ -260,7 +260,7 @@ def _validate_doc(model, doc):
"""
if not isinstance(doc, np.ndarray):
raise TypeError('doc must be a numpy.ndarray, got: {}'.format(doc))
input_sh = model.input_shape
input_sh = model.input.shape
doc_sh = doc.shape
if len(input_sh) == 4:
# rank 4 with (batch, ...) shape
Expand Down Expand Up @@ -337,6 +337,6 @@ def _is_suitable_activation_layer(model, layer):
# check layer name

# a check that asks "can we resize this activation layer over the image?"
rank = len(layer.output_shape)
required_rank = len(model.input_shape)
rank = len(layer.output.shape)
required_rank = len(model.input.shape)
return rank == required_rank
6 changes: 4 additions & 2 deletions tests/test_keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@
def simple_seq():
"""A simple sequential model for images."""
model = Sequential([
Activation('linear', input_shape=(32, 32, 1)), # index 0, input
Input((32, 32, 1)),
Activation('linear'), # index 0, input
conv_layer, # index 1, conv
Conv2D(20, (3, 3)), # index 2, conv2
GlobalAveragePooling2D(), # index 3, gap
# output shape is (None, 20)
])
model(Input((32, 32, 1)))
print('Summary of model:')
model.summary()
# rename layers
Expand Down Expand Up @@ -101,7 +103,7 @@ def test_validate_doc(simple_seq):

def test_validate_doc_custom():
# model with custom (not rank 4) input shape
model = Sequential([Dense(1, input_shape=(2, 3))])
model = Sequential(Input((2, 3)), [Dense(1)])
# not matching shape
with pytest.raises(ValueError):
_validate_doc(model, np.zeros((5, 3)))
Expand Down
Loading