BaseTextDetHead¶
- class mmocr.models.textdet.BaseTextDetHead(module_loss=None, postprocessor=None, init_cfg=None)[源代码]¶
Base head for text detection, build the loss and postprocessor.
1. The
init_weightsmethod is used to initialize head’s model parameters. After detector initialization,init_weightsis triggered whendetector.init_weights()is called externally.2. The
lossmethod is used to calculate the loss of head, which includes two steps: (1) the head model performs forward propagation to obtain the feature maps (2) Themodule_lossmethod is called based on the feature maps to calculate the loss.loss(): forward() -> module_loss()
3. The
predictmethod is used to predict detection results, which includes two steps: (1) the head model performs forward propagation to obtain the feature maps (2) Thepostprocessormethod is called based on the feature maps to predict detection results including post-processing.predict(): forward() -> postprocessor()
4. The
loss_and_predictmethod is used to return loss and detection results at the same time. It will call head’sforward,module_lossandpostprocessormethods in order.loss_and_predict(): forward() -> module_loss() -> postprocessor()
- 参数
- 返回类型
- loss(x, data_samples)[源代码]¶
Perform forward propagation and loss calculation of the detection head on the features of the upstream network.
- loss_and_predict(x, data_samples)[源代码]¶
Perform forward propagation of the head, then calculate loss and predictions from the features and data samples.
- 参数
x (tuple[Tensor]) – Features from FPN.
data_samples (list[
DetDataSample]) – Each item contains the meta information of each image and corresponding annotations.
- 返回
the return value is a tuple contains:
losses: (dict[str, Tensor]): A dictionary of loss components.
predictions (list[
InstanceData]): Detection results of each image after the post process.
- 返回类型
- predict(x, data_samples)[源代码]¶
Perform forward propagation of the detection head and predict detection results on the features of the upstream network.
- 参数
x (tuple[Tensor]) – Multi-level features from the upstream network, each is a 4D-tensor.
data_samples (List[
DetDataSample]) – The Data Samples. It usually includes information such as gt_instance, gt_panoptic_seg and gt_sem_seg.
- 返回
Detection results of each image after the post process.
- 返回类型
SampleList