Spaces:
Runtime error
Runtime error
File size: 1,625 Bytes
b34d1d6 |
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 51 52 53 54 55 56 57 58 |
import copy
import numpy as np
from mmcv import BaseTransform
from mmdet.registry import TRANSFORMS
from seg.models.utils import NO_OBJ
@TRANSFORMS.register_module()
class ImageCopy(BaseTransform):
"""Copy an image several times to build a video seq.
"""
DIVISOR = 10000
def __init__(
self,
num_frames: int = 1,
) -> None:
assert num_frames > 1
self.num_frames = num_frames
def transform(self, results: dict) -> dict:
for key in results:
value = results[key]
results[key] = []
for _ in range(self.num_frames):
results[key].append(copy.deepcopy(value))
num_instances = len(results['gt_bboxes_labels'][0])
num_frames = len(results['gt_bboxes_labels'])
gt_instance_ids = results['gt_bboxes_labels'][0] * self.DIVISOR + np.arange(num_instances) + 1
results['gt_instances_ids'] = [copy.deepcopy(gt_instance_ids) for _ in range(num_frames)]
return results
def __repr__(self) -> str:
repr_str = self.__class__.__name__
repr_str += f'(num_frames={self.num_frames})'
return repr_str
@TRANSFORMS.register_module()
class AddSemSeg(BaseTransform):
"""Add dummy semantic segmentation map.
"""
def __init__(self, ) -> None:
pass
def transform(self, results: dict) -> dict:
gt_seg = np.zeros(results['img'].shape[:2], dtype=np.int32) + NO_OBJ
results['gt_seg_map'] = gt_seg
return results
def __repr__(self) -> str:
repr_str = self.__class__.__name__
return repr_str
|