pipert.utils.structures.instances¶
Module Contents¶
Classes¶
This class represents a list of instances in an image. |
-
class
pipert.utils.structures.instances.Instances(image_size: Tuple[int, int], **kwargs: Any)[source]¶ 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 private: they must start with ‘_’ and are not modifiable by a user.
Some basic usage:
Set/Get a field: instances.gt_boxes = Boxes(…) print(instances.pred_masks) print(‘gt_masks’ in instances)
len(instances) returns the number of instances
Indexing: instances[indices] will apply the indexing on all the fields and returns a new Instances. Typically, indices is a binary vector of length num_instances, or a vector of integer indices.
-
set(self, name: str, value: Any) → None[source]¶ Set the field named name to value. The length of value must be the number of instances, and must agree with other existing fields in this object.
-
get_fields(self) → Dict[str, Any][source]¶ - Returns:
dict: a dict which maps names (str) to data of the fields
Modifying the returned dict will modify this instance.
-
to(self, device: str) → pipert.utils.structures.instances.Instances[source]¶ Returns: Instances: all fields are called with a to(device), if the field has this method.
-
__getitem__(self, item: Union[int, slice, torch.BoolTensor]) → pipert.utils.structures.instances.Instances[source]¶ - Args:
item: an index-like object and will be used to index all the fields.
- Returns:
If item is a string, return the data in the corresponding field. Otherwise, returns an Instances where all fields are indexed by item.
-
static
cat(instance_lists: List[‘Instances’]) → pipert.utils.structures.instances.Instances[source]¶ - Args:
instance_lists (list[Instances])
- Returns:
Instances