Define the coordinate mapping by its - axis - scale: output coord[i * scale] <- input_coord[i] - shift: output coord[i] <- output_coord[i + shift] s.t. the identity mapping, as for pointwise layers like ReLu, is defined by (None, 1, 0) since it is independent of axis and doe
(fn)
| 55 | |
| 56 | |
| 57 | def coord_map(fn): |
| 58 | """ |
| 59 | Define the coordinate mapping by its |
| 60 | - axis |
| 61 | - scale: output coord[i * scale] <- input_coord[i] |
| 62 | - shift: output coord[i] <- output_coord[i + shift] |
| 63 | s.t. the identity mapping, as for pointwise layers like ReLu, is defined by |
| 64 | (None, 1, 0) since it is independent of axis and does not transform coords. |
| 65 | """ |
| 66 | if fn.type_name in ['Convolution', 'Pooling', 'Im2col']: |
| 67 | axis, stride, ks, pad = conv_params(fn) |
| 68 | return axis, 1 / stride, (pad - (ks - 1) / 2) / stride |
| 69 | elif fn.type_name == 'Deconvolution': |
| 70 | axis, stride, ks, pad = conv_params(fn) |
| 71 | return axis, stride, (ks - 1) / 2 - pad |
| 72 | elif fn.type_name in PASS_THROUGH_LAYERS: |
| 73 | return None, 1, 0 |
| 74 | elif fn.type_name == 'Crop': |
| 75 | axis, offset = crop_params(fn) |
| 76 | axis -= 1 # -1 for last non-coordinate dim. |
| 77 | return axis, 1, - offset |
| 78 | else: |
| 79 | raise UndefinedMapException |
| 80 | |
| 81 | |
| 82 | class AxisMismatchException(Exception): |
no test coverage detected