Skip to content

Commit

Permalink
[pycaffe] align coord_map and BVLC#3570 Crop layer
Browse files Browse the repository at this point in the history
- crop -> offset
- adjust crop axis by 1
  • Loading branch information
shelhamer authored and zouxiaochuan committed Mar 17, 2016
1 parent d4d3a2d commit bdb72aa
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions python/caffe/coord_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))))

0 comments on commit bdb72aa

Please sign in to comment.