From 32fefa96f9ba585bbbf4fff19fef89c3ec125a89 Mon Sep 17 00:00:00 2001 From: Jonathan L Long Date: Fri, 18 Jul 2014 16:32:12 -0700 Subject: [PATCH] pycaffe: reorder exceptions It doesn't make sense to complain about input not being batch-sized if it isn't even 4-d in the first place. --- python/caffe/pycaffe.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/caffe/pycaffe.py b/python/caffe/pycaffe.py index a2fb16ba..dde838d6 100644 --- a/python/caffe/pycaffe.py +++ b/python/caffe/pycaffe.py @@ -57,10 +57,10 @@ def _Net_forward(self, blobs=None, **kwargs): # Set input according to defined shapes and make arrays single and # C-contiguous as Caffe expects. for in_, blob in kwargs.iteritems(): - if blob.shape[0] != self.blobs[in_].num: - raise Exception('Input is not batch sized') if blob.ndim != 4: raise Exception('{} blob is not 4-d'.format(in_)) + if blob.shape[0] != self.blobs[in_].num: + raise Exception('Input is not batch sized') self.blobs[in_].data[...] = blob self._forward() @@ -91,10 +91,10 @@ def _Net_backward(self, diffs=None, **kwargs): # Set top diffs according to defined shapes and make arrays single and # C-contiguous as Caffe expects. for top, diff in kwargs.iteritems(): - if diff.shape[0] != self.blobs[top].num: - raise Exception('Diff is not batch sized') if diff.ndim != 4: raise Exception('{} diff is not 4-d'.format(top)) + if diff.shape[0] != self.blobs[top].num: + raise Exception('Diff is not batch sized') self.blobs[top].diff[...] = diff self._backward()