You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

demodata.py 1.2 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright (c) OpenMMLab. All rights reserved.
  2. import numpy as np
  3. import torch
  4. from mmdet.utils.util_random import ensure_rng
  5. def random_boxes(num=1, scale=1, rng=None):
  6. """Simple version of ``kwimage.Boxes.random``
  7. Returns:
  8. Tensor: shape (n, 4) in x1, y1, x2, y2 format.
  9. References:
  10. https://gitlab.kitware.com/computer-vision/kwimage/blob/master/kwimage/structs/boxes.py#L1390
  11. Example:
  12. >>> num = 3
  13. >>> scale = 512
  14. >>> rng = 0
  15. >>> boxes = random_boxes(num, scale, rng)
  16. >>> print(boxes)
  17. tensor([[280.9925, 278.9802, 308.6148, 366.1769],
  18. [216.9113, 330.6978, 224.0446, 456.5878],
  19. [405.3632, 196.3221, 493.3953, 270.7942]])
  20. """
  21. rng = ensure_rng(rng)
  22. tlbr = rng.rand(num, 4).astype(np.float32)
  23. tl_x = np.minimum(tlbr[:, 0], tlbr[:, 2])
  24. tl_y = np.minimum(tlbr[:, 1], tlbr[:, 3])
  25. br_x = np.maximum(tlbr[:, 0], tlbr[:, 2])
  26. br_y = np.maximum(tlbr[:, 1], tlbr[:, 3])
  27. tlbr[:, 0] = tl_x * scale
  28. tlbr[:, 1] = tl_y * scale
  29. tlbr[:, 2] = br_x * scale
  30. tlbr[:, 3] = br_y * scale
  31. boxes = torch.from_numpy(tlbr)
  32. return boxes

No Description

Contributors (1)