Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,567 Bytes
fb9d4c3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# Copyright (c) Facebook, Inc. and its affiliates.
from typing import Any, Tuple
from detectron2.structures import BitMasks, Boxes
from .base import BaseConverter
ImageSizeType = Tuple[int, int]
class ToMaskConverter(BaseConverter):
"""
Converts various DensePose predictor outputs to masks
in bit mask format (see `BitMasks`). Each DensePose predictor output type
has to register its convertion strategy.
"""
registry = {}
dst_type = BitMasks
@classmethod
# pyre-fixme[14]: `convert` overrides method defined in `BaseConverter`
# inconsistently.
def convert(
cls,
densepose_predictor_outputs: Any,
boxes: Boxes,
image_size_hw: ImageSizeType,
*args,
**kwargs
) -> BitMasks:
"""
Convert DensePose predictor outputs to BitMasks using some registered
converter. Does recursive lookup for base classes, so there's no need
for explicit registration for derived classes.
Args:
densepose_predictor_outputs: DensePose predictor output to be
converted to BitMasks
boxes (Boxes): bounding boxes that correspond to the DensePose
predictor outputs
image_size_hw (tuple [int, int]): image height and width
Return:
An instance of `BitMasks`. If no suitable converter was found, raises KeyError
"""
return super(ToMaskConverter, cls).convert(
densepose_predictor_outputs, boxes, image_size_hw, *args, **kwargs
)
|