Skip to content
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

NetSpec: type-check Function inputs (they must be Top instances) #3153

Merged
merged 1 commit into from
Apr 14, 2017
Merged
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
NetSpec: type-check Function inputs (they must be Top instances)
  • Loading branch information
jeffdonahue committed Oct 6, 2015
commit 10725393518df14b9b6976686f72fae792c3f393
4 changes: 4 additions & 0 deletions python/caffe/net_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ class Function(object):

def __init__(self, type_name, inputs, params):
self.type_name = type_name
for index, input in enumerate(inputs):
if not isinstance(input, Top):
raise TypeError('%s input %d is not a Top (type is %s)' %
(type_name, index, type(input)))
self.inputs = inputs
self.params = params
self.ntop = self.params.get('ntop', 1)
Expand Down
8 changes: 8 additions & 0 deletions python/caffe/test/test_net_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,11 @@ def test_zero_tops(self):
net_proto = silent_net()
net = self.load_net(net_proto)
self.assertEqual(len(net.forward()), 0)

def test_type_error(self):
"""Test that a TypeError is raised when a Function input isn't a Top."""
data = L.DummyData(ntop=2) # data is a 2-tuple of Tops
r = r"^Silence input 0 is not a Top \(type is <(type|class) 'tuple'>\)$"
with self.assertRaisesRegexp(TypeError, r):
L.Silence(data, ntop=0) # should raise: data is a tuple, not a Top
L.Silence(*data, ntop=0) # shouldn't raise: each elt of data is a Top