MMDetWrapper¶
- class mmocr.models.textdet.MMDetWrapper(cfg, text_repr_type='poly')[源代码]¶
A wrapper of MMDet’s model.
- 参数
- 返回类型
- adapt_predictions(data, data_samples)[源代码]¶
Convert Instance datas from MMDet into MMOCR’s format.
- 参数
data (List[mmdet.structures.det_data_sample.DetDataSample]) –
(list[DetDataSample]): Detection results of the input images. Each DetDataSample usually contain ‘pred_instances’. And the
pred_instances
usually contains following keys. - scores (Tensor): Classification scores, has a shape(num_instance, )
- labels (Tensor): Labels of bboxes, has a shape
(num_instances, ).
- bboxes (Tensor): Has a shape (num_instances, 4),
the last dimension 4 arrange as (x1, y1, x2, y2).
masks (Tensor, Optional): Has a shape (num_instances, H, W).
data_samples (list[
TextDetDataSample
]) – The annotation data of every samples.
- 返回
- A list of N datasamples containing ground
truth and prediction results. The polygon results are saved in
TextDetDataSample.pred_instances.polygons
The confidence scores are saved inTextDetDataSample.pred_instances.scores
.
- 返回类型
- forward(inputs, data_samples=None, mode='tensor', **kwargs)[源代码]¶
The unified entry for a forward process in both training and test.
The method works in three modes: “tensor”, “predict” and “loss”:
“tensor”: Forward the whole network and return tensor or tuple of
tensor without any post-processing, same as a common nn.Module. - “predict”: Forward and return the predictions, which are fully processed to a list of
DetDataSample
. - “loss”: Forward and return a dict of losses according to the given inputs and data samples.Note that this method doesn’t handle either back propagation or parameter update, which are supposed to be done in
train_step()
.- 参数
inputs (torch.Tensor) – The input tensor with shape (N, C, …) in general.
data_samples (Optional[Union[List[mmocr.structures.textdet_data_sample.TextDetDataSample], List[mmdet.structures.det_data_sample.DetDataSample]]]) –
mode (str) –
- 返回类型
Union[Dict[str, torch.Tensor], List[mmdet.structures.det_data_sample.DetDataSample], Tuple[torch.Tensor], torch.Tensor]
- :param data_samples (list[
DetDataSample
] or: list[TextDetDataSample
]): The annotation data of every sample. When in “predict” mode, it should be a list of
TextDetDataSample
. Otherwise they are :obj:`DetDataSample`s. Defaults to None.
- 参数
mode (str) – Running mode. Defaults to ‘tensor’.
inputs (torch.Tensor) –
data_samples (Optional[Union[List[mmocr.structures.textdet_data_sample.TextDetDataSample], List[mmdet.structures.det_data_sample.DetDataSample]]]) –
- 返回
The return type depends on
mode
.If
mode="tensor"
, return a tensor or a tuple of tensor.If
mode="predict"
, return a list ofTextDetDataSample
.If
mode="loss"
, return a dict of tensor.
- 返回类型
Union[Dict[str, torch.Tensor], List[mmdet.structures.det_data_sample.DetDataSample], Tuple[torch.Tensor], torch.Tensor]