pipert.utils.structures.instances

Module Contents

Classes

Instances

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:

  1. Set/Get a field: instances.gt_boxes = Boxes(…) print(instances.pred_masks) print(‘gt_masks’ in instances)

  2. len(instances) returns the number of instances

  3. 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.

property image_size(self)Tuple[int, int][source]

Returns: tuple: height, width

__setattr__(self, name: str, val: Any)None[source]

Implement setattr(self, name, value).

__getattr__(self, name: str)Any[source]
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.

has(self, name: str)bool[source]

Returns: bool: whether the field called name exists.

remove(self, name: str)None[source]

Remove the field called name.

get(self, name: str)Any[source]

Returns the field called name.

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.

__len__(self)int[source]
static cat(instance_lists: List[‘Instances’])pipert.utils.structures.instances.Instances[source]
Args:

instance_lists (list[Instances])

Returns:

Instances

__str__(self)str[source]

Return str(self).

__repr__(self)str[source]

Return repr(self).