Skip to content

Commit

Permalink
Format state_spec in the error message (keras-team#9035)
Browse files Browse the repository at this point in the history
* Implement __repr__ for InputSpec

* Error message
  • Loading branch information
myutwo150 authored and fchollet committed Jan 10, 2018
1 parent 0a32488 commit 7591740
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions keras/engine/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ def __init__(self, dtype=None,
self.min_ndim = min_ndim
self.axes = axes or {}

def __repr__(self):
spec = [('dtype=' + str(self.dtype)) if self.dtype else '',
('shape=' + str(self.shape)) if self.shape else '',
('ndim=' + str(self.ndim)) if self.ndim else '',
('max_ndim=' + str(self.max_ndim)) if self.max_ndim else '',
('min_ndim=' + str(self.min_ndim)) if self.min_ndim else '',
('axes=' + str(self.axes)) if self.axes else '']
return 'InputSpec(%s)' % ', '.join(x for x in spec if x)


class Node(object):
"""A `Node` describes the connectivity between two layers.
Expand Down
4 changes: 2 additions & 2 deletions keras/layers/recurrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,9 @@ def build(self, input_shape):
# initial_state was passed in call, check compatibility
if [spec.shape[-1] for spec in self.state_spec] != state_size:
raise ValueError(
'An initial_state was passed that is not compatible with '
'An `initial_state` was passed that is not compatible with '
'`cell.state_size`. Received `state_spec`={}; '
'However `cell.state_size` is '
'however `cell.state_size` is '
'{}'.format(self.state_spec, self.cell.state_size))
else:
self.state_spec = [InputSpec(shape=(None, dim))
Expand Down

0 comments on commit 7591740

Please sign in to comment.