[pycaffe] align coord_map and #3570 Crop layer
authorEvan Shelhamer <shelhamer@imaginarynumber.net>
Sun, 28 Feb 2016 19:51:52 +0000 (11:51 -0800)
committerEvan Shelhamer <shelhamer@imaginarynumber.net>
Sat, 5 Mar 2016 03:09:51 +0000 (19:09 -0800)
- crop -> offset
- adjust crop axis by 1

python/caffe/coord_map.py

index 884d907..a3413cf 100644 (file)
@@ -73,6 +73,7 @@ def coord_map(fn):
         return None, 1, 0
     elif fn.type_name == 'Crop':
         axis, offset = crop_params(fn)
+        axis -= 1  # -1 for last non-coordinate dim.
         return axis, 1, - offset
     else:
         raise UndefinedMapException
@@ -176,9 +177,9 @@ def crop(top_from, top_to):
     """
     ax, a, b = coord_map_from_to(top_from, top_to)
     assert (a == 1).all(), 'scale mismatch on crop (a = {})'.format(a)
-    assert (b <= 0).all(), 'cannot crop negative width (b = {})'.format(b)
-    assert (np.round(b) == b).all(), 'cannot crop noninteger width ' \
+    assert (b <= 0).all(), 'cannot crop negative offset (b = {})'.format(b)
+    assert (np.round(b) == b).all(), 'cannot crop noninteger offset ' \
         '(b = {})'.format(b)
     return L.Crop(top_from, top_to,
-                  crop_param=dict(axis=ax,
-                                  crop=list(-np.round(b).astype(int))))
+                  crop_param=dict(axis=ax + 1,  # +1 for first cropping dim.
+                                  offset=list(-np.round(b).astype(int))))