(model, model_path, images, ground_truth=None)
| 15 | |
| 16 | |
| 17 | def apply(model, model_path, images, ground_truth=None): |
| 18 | left = cv2.imread(images[0]) |
| 19 | h, w = left.shape[:2] |
| 20 | newh = (h // 64) * 64 |
| 21 | neww = (w // 64) * 64 |
| 22 | aug = imgaug.CenterCrop((newh, neww)) |
| 23 | left = aug.augment(left) |
| 24 | |
| 25 | predict_func = OfflinePredictor(PredictConfig( |
| 26 | model=model(height=newh, width=neww), |
| 27 | session_init=SmartInit(model_path), |
| 28 | input_names=['left', 'right'], |
| 29 | output_names=['prediction'])) |
| 30 | |
| 31 | for idx, right in enumerate(images[1:]): |
| 32 | right = aug.augment(cv2.imread(right)) |
| 33 | |
| 34 | left_input, right_input = [x.astype('float32').transpose(2, 0, 1)[None, ...] |
| 35 | for x in [left, right]] |
| 36 | output = predict_func(left_input, right_input)[0].transpose(0, 2, 3, 1) |
| 37 | flow = Flow() |
| 38 | |
| 39 | img = flow.visualize(output[0]) |
| 40 | patches = [left, right, img * 255.] |
| 41 | if ground_truth is not None: |
| 42 | patches.append(flow.visualize(Flow.read(ground_truth)) * 255.) |
| 43 | img = viz.stack_patches(patches, 2, 2) |
| 44 | |
| 45 | cv2.imshow('flow output', img) |
| 46 | cv2.imwrite('flow_output{:03d}.png'.format(idx), img) |
| 47 | cv2.waitKey(0) |
| 48 | |
| 49 | left = right |
| 50 | |
| 51 | |
| 52 | class SintelData(DataFlow): |
no test coverage detected
searching dependent graphs…