MCPcopy Create free account
hub / github.com/Robbyant/lingbot-map / prepare_for_visualization

Function prepare_for_visualization

demo.py:307–335  ·  view source on GitHub ↗

Convert predictions to the unbatched NumPy format used by vis code.

(predictions, images=None)

Source from the content-addressed store, hash-verified

305
306
307def prepare_for_visualization(predictions, images=None):
308 """Convert predictions to the unbatched NumPy format used by vis code."""
309 vis_predictions = {}
310 for k, v in predictions.items():
311 if isinstance(v, torch.Tensor):
312 v = _squeeze_single_batch(k, v.detach().cpu())
313 vis_predictions[k] = v.numpy()
314 elif isinstance(v, np.ndarray):
315 vis_predictions[k] = _squeeze_single_batch(k, v)
316 else:
317 vis_predictions[k] = v
318
319 if images is None:
320 images = predictions.get("images")
321
322 if isinstance(images, torch.Tensor):
323 images = images.detach().cpu()
324 if isinstance(images, np.ndarray):
325 images = _squeeze_single_batch("images", images)
326 elif isinstance(images, torch.Tensor):
327 images = _squeeze_single_batch("images", images).numpy()
328
329 if isinstance(images, torch.Tensor):
330 images = images.numpy()
331
332 if images is not None:
333 vis_predictions["images"] = images
334
335 return vis_predictions
336
337
338# =============================================================================

Callers 1

mainFunction · 0.70

Calls 1

_squeeze_single_batchFunction · 0.70

Tested by

no test coverage detected