MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / Instances

Class Instances

PATH/core/data/datasets/images/seg_dataset_dev.py:13–198  ·  view source on GitHub ↗

This class represents a list of instances in an image. It stores the attributes of instances (e.g., boxes, masks, labels, scores) as "fields". All fields must have the same ``__len__`` which is the number of instances. All other (non-field) attributes of this class are considered p

Source from the content-addressed store, hash-verified

11
12
13class Instances:
14 """
15 This class represents a list of instances in an image.
16 It stores the attributes of instances (e.g., boxes, masks, labels, scores) as "fields".
17 All fields must have the same ``__len__`` which is the number of instances.
18
19 All other (non-field) attributes of this class are considered private:
20 they must start with '_' and are not modifiable by a user.
21
22 Some basic usage:
23
24 1. Set/get/check a field:
25
26 .. code-block:: python
27
28 instances.gt_boxes = Boxes(...)
29 print(instances.pred_masks) # a tensor of shape (N, H, W)
30 print('gt_masks' in instances)
31
32 2. ``len(instances)`` returns the number of instances
33 3. Indexing: ``instances[indices]`` will apply the indexing on all the fields
34 and returns a new :class:`Instances`.
35 Typically, ``indices`` is a integer vector of indices,
36 or a binary mask of length ``num_instances``
37
38 .. code-block:: python
39
40 category_3_detections = instances[instances.pred_classes == 3]
41 confident_detections = instances[instances.scores > 0.9]
42 """
43
44 def __init__(self, image_size: Tuple[int, int], **kwargs: Any):
45 """
46 Args:
47 image_size (height, width): the spatial size of the image.
48 kwargs: fields to add to this `Instances`.
49 """
50 self._image_size = image_size
51 self._fields: Dict[str, Any] = {}
52 for k, v in kwargs.items():
53 self.set(k, v)
54
55 @property
56 def image_size(self) -> Tuple[int, int]:
57 """
58 Returns:
59 tuple: height, width
60 """
61 return self._image_size
62
63 def __setattr__(self, name: str, val: Any) -> None:
64 if name.startswith("_"):
65 super().__setattr__(name, val)
66 else:
67 self.set(name, val)
68
69 def __getattr__(self, name: str) -> Any:
70 if name == "_fields" or name not in self._fields:

Callers 6

__getitem__Method · 0.90
__getitem__Method · 0.90
__getitem__Method · 0.90
cudaMethod · 0.85
__getitem__Method · 0.85
catMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected