pycaffe: test channel_order and input_scale against None
authorJonathan L Long <jonlong@cs.berkeley.edu>
Fri, 18 Jul 2014 23:45:17 +0000 (16:45 -0700)
committerJonathan L Long <jonlong@cs.berkeley.edu>
Sat, 19 Jul 2014 00:08:49 +0000 (17:08 -0700)
An input_scale of zero should produce warnings/errors/infinities rather
than being the same as an input_scale of one. A channel_order of () or 0
should not be equivalent to the default ordering.

python/caffe/pycaffe.py

index dde838d..5f04a95 100644 (file)
@@ -262,9 +262,9 @@ def _Net_preprocess(self, input_name, input_):
     in_size = self.blobs[input_name].data.shape[2:]
     if caffe_in.shape[:2] != in_size:
         caffe_in = caffe.io.resize_image(caffe_in, in_size)
-    if input_scale:
+    if input_scale is not None:
         caffe_in *= input_scale
-    if channel_order:
+    if channel_order is not None:
         caffe_in = caffe_in[:, :, channel_order]
     caffe_in = caffe_in.transpose((2, 0, 1))
     if hasattr(self, 'mean'):
@@ -282,11 +282,11 @@ def _Net_deprocess(self, input_name, input_):
     if hasattr(self, 'mean'):
         decaf_in += self.mean.get(input_name, 0)
     decaf_in = decaf_in.transpose((1,2,0))
-    if channel_order:
+    if channel_order is not None:
         channel_order_inverse = [channel_order.index(i)
                                  for i in range(decaf_in.shape[2])]
         decaf_in = decaf_in[:, :, channel_order_inverse]
-    if input_scale:
+    if input_scale is not None:
         decaf_in /= input_scale
     return decaf_in