Define a Crop layer to crop a top (from) to another top (to) by determining the coordinate mapping between the two and net spec'ing the axis and shift parameters of the crop.
(top_from, top_to)
| 170 | |
| 171 | |
| 172 | def crop(top_from, top_to): |
| 173 | """ |
| 174 | Define a Crop layer to crop a top (from) to another top (to) by |
| 175 | determining the coordinate mapping between the two and net spec'ing |
| 176 | the axis and shift parameters of the crop. |
| 177 | """ |
| 178 | ax, a, b = coord_map_from_to(top_from, top_to) |
| 179 | assert (a == 1).all(), 'scale mismatch on crop (a = {})'.format(a) |
| 180 | assert (b <= 0).all(), 'cannot crop negative offset (b = {})'.format(b) |
| 181 | assert (np.round(b) == b).all(), 'cannot crop noninteger offset ' \ |
| 182 | '(b = {})'.format(b) |
| 183 | return L.Crop(top_from, top_to, |
| 184 | crop_param=dict(axis=ax + 1, # +1 for first cropping dim. |
| 185 | offset=list(-np.round(b).astype(int)))) |