MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / predict_image

Function predict_image

examples/FasterRCNN/eval.py:109–141  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

107
108
109def 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
144def predict_dataflow(df, model_func, tqdm_bar=None):

Callers 4

evaluate_rcnnFunction · 0.90
do_predictFunction · 0.90
predict.pyFile · 0.90
predict_dataflowFunction · 0.85

Calls 5

CustomResizeClass · 0.90
clip_boxesFunction · 0.90
model_funcFunction · 0.85
_paste_maskFunction · 0.85
augmentMethod · 0.80

Tested by

no test coverage detected