consnet.api.data

consnet.api.data.convert_anno(anno_file, out_file, split)[source]

Convert annotations of HICO-DET [1] dataset to COCO [2] format.

Parameters
  • anno_file (str) – Path to the anno_bbox.mat file.

  • out_file (str) – Path to the output file. The filename must end with '.json'.

  • split (str) – The dataset split to be converted. Expected values are 'train' and 'test'.

References

  1. Chao et al. (https://arxiv.org/abs/1702.05448)

  2. Lin et al. (https://arxiv.org/abs/1405.0312)

consnet.api.data.load_anno(anno_file, split)[source]

Load annotations of HICO-DET [1] dataset.

The loaded annotations will be stored in an N * 10 tensor whose rows are in (img_id, hoi_idx, human_bbox, object_bbox) format. The hoi_idx will be in the range of 0 ~ 599 and the bboxes will be in xyxy style. Invisible human-object pairs will be discarded.

Parameters
  • anno_file (str) – Path to the anno_bbox.mat file.

  • split (str) – The dataset split to be loaded. Expected values are 'train' and 'test'.

Returns

The loaded annotations.

Return type

Tensor[N, 10]

Example

>>> anno = load_anno('<path-to-anno_bbox.mat>', 'train')
>>> print(anno)
... tensor([[img_id_1, hoi_idx_1, human_bbox_1, object_bbox_1]
...         [img_id_2, hoi_idx_2, human_bbox_2, object_bbox_2]
...         [img_id_3, hoi_idx_3, human_bbox_3, object_bbox_3]])

References

  1. Chao et al. (https://arxiv.org/abs/1702.05448)

consnet.api.data.obj_idx_to_coco_id(obj_idx)[source]

Convert object index (0 ~ 79) to COCO id (90 classes).

Parameters

obj_idx (list[int] or int) – The object index or list of object indexes.

Returns

The converted COCO id or list of COCO ids.

Return type

list[int] or int

consnet.api.data.hoi_idx_to_coco_id(hoi_idx)[source]

Convert HOI index (0 ~ 599) to COCO id (90 classes).

Parameters

hoi_idx (list[int] or int) – The HOI index or list of HOI indexes.

Returns

The converted COCO id or list of COCO ids.

Return type

list[int] or int

consnet.api.data.hoi_idx_to_act_idx(hoi_idx)[source]

Convert HOI index (0 ~ 599) to action index (0 ~ 116).

Parameters

hoi_idx (list[int] or int) – The HOI index or list of HOI indexes.

Returns

The converted action index or list of action indexes.

Return type

list[int] or int

consnet.api.data.hoi_idx_to_obj_idx(hoi_idx)[source]

Convert HOI index (0 ~ 599) to object index (0 ~ 79).

Parameters

hoi_idx (list[int] or int) – The HOI index or list of HOI indexes.

Returns

The converted object index or list of object indexes.

Return type

list[int] or int

consnet.api.data.act_idx_to_hoi_idx(act_idx)[source]

Convert action index (0 ~ 116) to HOI index (0 ~ 599).

Parameters

act_idx (list[int] or int) – The action index or list of action indexes.

Returns

The converted HOI indexes.

Return type

list[list] or list[int]

consnet.api.data.obj_idx_to_hoi_idx(obj_idx)[source]

Convert object index (0 ~ 79) to HOI index (0 ~ 599).

Parameters

obj_idx (list[int] or int) – The object index or list of object indexes.

Returns

The converted HOI indexes.

Return type

list[list] or list[int]

consnet.api.data.get_act_name(act_idx)[source]

Get action name according to action index (0 ~ 116).

Parameters

act_idx (int) – The action index.

Returns

The action name.

Return type

str

consnet.api.data.get_obj_name(obj_idx)[source]

Get object name according to object index (0 ~ 79).

Parameters

act_idx (int) – The object index.

Returns

The object name.

Return type

str

consnet.api.data.get_act_and_obj_name(hoi_idx)[source]

Get action and object name according to HOI index (0 ~ 599).

Parameters

hoi_idx (int) – The HOI index.

Returns

The action and object name.

Return type

tuple[str]

consnet.api.data.get_hoi_name(hoi_idx)[source]

Get HOI name according to HOI index (0 ~ 599).

Parameters

hoi_idx (int) – The HOI index.

Returns

The HOI name.

Return type

str

consnet.api.data.get_rare_hoi_idx()[source]

Get rare HOI indexes (0 ~ 599).

Returns

The list of rare HOI indexes.

Return type

list[int]

consnet.api.data.get_non_rare_hoi_idx()[source]

Get non-rare HOI indexes (0 ~ 599).

Returns

The list of non-rare HOI indexes.

Return type

list[int]

consnet.api.data.get_seen_hoi_idx(type, id=None)[source]

Get seen HOI indexes (0 ~ 599).

Parameters
  • type (str) – Type of the zero-shot scenario. Expected values include 'uc', 'uo' and 'ua', representing unseen action-object combination, unseen object and unseen action scenarios.

  • id (int, optional) – Only valid when type='uc'. Expected values are in the range of 0 ~ 4, indicating the 5 groups of unseen action-object combination settings in [1, 2].

Returns

The list of seen HOI indexes.

Return type

list[int]

References

  1. Liu et al. (https://arxiv.org/abs/2008.06254)

  2. Bansal et al. (https://arxiv.org/abs/1904.03181)

consnet.api.data.get_unseen_hoi_idx(type, id=None)[source]

Get unseen HOI indexes (0 ~ 599).

Parameters
  • type (str) – Type of the zero-shot scenario. Expected values include 'uc', 'uo' and 'ua', representing unseen action-object combination, unseen object and unseen action scenarios.

  • id (int, optional) – Only valid when type='uc'. Expected values are in the range of 0 ~ 4, indicating the 5 groups of unseen action-object combination settings in [1, 2].

Returns

The list of unseen HOI indexes.

Return type

list[int]

References

  1. Liu et al. (https://arxiv.org/abs/2008.06254)

  2. Bansal et al. (https://arxiv.org/abs/1904.03181)

consnet.api.data.scatter_hum_to_hoi(tensor)[source]

Scatter human to HOI classes.

Parameters

tensor (torch.Tensor[N, 1]) – The input tensor.

Returns

The scattered tensor.

Return type

torch.Tensor[N, 600]

consnet.api.data.scatter_act_to_hoi(tensor)[source]

Scatter action classes to HOI classes.

Parameters

tensor (torch.Tensor[N, 117]) – The input tensor.

Returns

The scattered tensor.

Return type

torch.Tensor[N, 600]

consnet.api.data.scatter_obj_to_hoi(tensor)[source]

Scatter object classes to HOI classes.

Parameters

tensor (torch.Tensor[N, 80]) – The input tensor.

Returns

The scattered tensor.

Return type

torch.Tensor[N, 600]