(modelpath)
| 202 | |
| 203 | |
| 204 | def view_warp(modelpath): |
| 205 | pred = OfflinePredictor(PredictConfig( |
| 206 | session_init=SmartInit(modelpath), |
| 207 | model=Model(), |
| 208 | input_names=['input'], |
| 209 | output_names=['visualization/viz', 'STN1/affine', 'STN2/affine'])) |
| 210 | |
| 211 | xys = np.array([[0, 0, 1], |
| 212 | [WARP_TARGET_SIZE, 0, 1], |
| 213 | [WARP_TARGET_SIZE, WARP_TARGET_SIZE, 1], |
| 214 | [0, WARP_TARGET_SIZE, 1]], dtype='float32') |
| 215 | |
| 216 | def draw_rect(img, affine, c, offset=(0, 0)): |
| 217 | a = np.transpose(affine) # 3x2 |
| 218 | a = (np.matmul(xys, a) + list(offset)).astype('int32') |
| 219 | cv2.line(img, tuple(a[0][::-1]), tuple(a[1][::-1]), c) |
| 220 | cv2.line(img, tuple(a[1][::-1]), tuple(a[2][::-1]), c) |
| 221 | cv2.line(img, tuple(a[2][::-1]), tuple(a[3][::-1]), c) |
| 222 | cv2.line(img, tuple(a[3][::-1]), tuple(a[0][::-1]), c) |
| 223 | |
| 224 | ds = get_data(False) |
| 225 | ds.reset_state() |
| 226 | for k in ds: |
| 227 | img, label = k |
| 228 | outputs, affine1, affine2 = pred(img) |
| 229 | for idx, viz in enumerate(outputs): |
| 230 | viz = cv2.cvtColor(viz, cv2.COLOR_GRAY2BGR) |
| 231 | # Here we assume the second branch focuses on the first digit |
| 232 | draw_rect(viz, affine2[idx], (0, 0, 255)) |
| 233 | draw_rect(viz, affine1[idx], (0, 0, 255), offset=[IMAGE_SIZE, 0]) |
| 234 | cv2.imwrite('{:03d}.png'.format(idx), (viz + 0.5) * 255) |
| 235 | break |
| 236 | |
| 237 | |
| 238 | def get_config(): |
no test coverage detected
searching dependent graphs…