Run detection on one image, using the TF callable. This function should handle the preprocessing internally. Args: img: an image model_func: a callable from the TF model. It takes image and returns (boxes, probs, labels, [masks]) Returns: [Detec
(img, model_func)
| 107 | |
| 108 | |
| 109 | def predict_image(img, model_func): |
| 110 | """ |
| 111 | Run detection on one image, using the TF callable. |
| 112 | This function should handle the preprocessing internally. |
| 113 | |
| 114 | Args: |
| 115 | img: an image |
| 116 | model_func: a callable from the TF model. |
| 117 | It takes image and returns (boxes, probs, labels, [masks]) |
| 118 | |
| 119 | Returns: |
| 120 | [DetectionResult] |
| 121 | """ |
| 122 | orig_shape = img.shape[:2] |
| 123 | resizer = CustomResize(cfg.PREPROC.TEST_SHORT_EDGE_SIZE, cfg.PREPROC.MAX_SIZE) |
| 124 | resized_img = resizer.augment(img) |
| 125 | scale = np.sqrt(resized_img.shape[0] * 1.0 / img.shape[0] * resized_img.shape[1] / img.shape[1]) |
| 126 | boxes, probs, labels, *masks = model_func(resized_img) |
| 127 | |
| 128 | # Some slow numpy postprocessing: |
| 129 | boxes = boxes / scale |
| 130 | # boxes are already clipped inside the graph, but after the floating point scaling, this may not be true any more. |
| 131 | boxes = clip_boxes(boxes, orig_shape) |
| 132 | if masks: |
| 133 | full_masks = [_paste_mask(box, mask, orig_shape) |
| 134 | for box, mask in zip(boxes, masks[0])] |
| 135 | masks = full_masks |
| 136 | else: |
| 137 | # fill with none |
| 138 | masks = [None] * len(boxes) |
| 139 | |
| 140 | results = [DetectionResult(*args) for args in zip(boxes, probs, labels.tolist(), masks)] |
| 141 | return results |
| 142 | |
| 143 | |
| 144 | def predict_dataflow(df, model_func, tqdm_bar=None): |
no test coverage detected