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

Function predict_dataflow

examples/FasterRCNN/eval.py:144–182  ·  view source on GitHub ↗

Args: df: a DataFlow which produces (image, image_id) model_func: a callable from the TF model. It takes image and returns (boxes, probs, labels, [masks]) tqdm_bar: a tqdm object to be shared among multiple evaluation instances. If None, will crea

(df, model_func, tqdm_bar=None)

Source from the content-addressed store, hash-verified

142
143
144def predict_dataflow(df, model_func, tqdm_bar=None):
145 """
146 Args:
147 df: a DataFlow which produces (image, image_id)
148 model_func: a callable from the TF model.
149 It takes image and returns (boxes, probs, labels, [masks])
150 tqdm_bar: a tqdm object to be shared among multiple evaluation instances. If None,
151 will create a new one.
152
153 Returns:
154 list of dict, in the format used by
155 `DatasetSplit.eval_inference_results`
156 """
157 df.reset_state()
158 all_results = []
159 with ExitStack() as stack:
160 # tqdm is not quite thread-safe: https://github.com/tqdm/tqdm/issues/323
161 if tqdm_bar is None:
162 tqdm_bar = stack.enter_context(get_tqdm(total=df.size()))
163 for img, img_id in df:
164 results = predict_image(img, model_func)
165 for r in results:
166 # int()/float() to make it json-serializable
167 res = {
168 'image_id': img_id,
169 'category_id': int(r.class_id),
170 'bbox': [round(float(x), 4) for x in r.box],
171 'score': round(float(r.score), 4),
172 }
173
174 # also append segmentation to results
175 if r.mask is not None:
176 rle = cocomask.encode(
177 np.array(r.mask[:, :, None], order='F'))[0]
178 rle['counts'] = rle['counts'].decode('ascii')
179 res['segmentation'] = rle
180 all_results.append(res)
181 tqdm_bar.update(1)
182 return all_results
183
184
185def multithread_predict_dataflow(dataflows, model_funcs):

Callers 2

_evalMethod · 0.85

Calls 6

get_tqdmFunction · 0.90
predict_imageFunction · 0.85
appendMethod · 0.80
updateMethod · 0.80
reset_stateMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected