PaddleOCR/ppocr/losses/__init__.py

125 lines
3.3 KiB
Python
Raw Normal View History

# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2020-10-13 17:13:33 +08:00
import copy
2021-06-02 16:31:57 +08:00
import paddle
import paddle.nn as nn
2020-10-13 17:13:33 +08:00
# basic_loss
from .basic_loss import LossFromOutput
2021-06-02 16:31:57 +08:00
# det loss
from .det_db_loss import DBLoss
from .det_east_loss import EASTLoss
from .det_sast_loss import SASTLoss
2021-07-27 15:33:05 +08:00
from .det_pse_loss import PSELoss
2022-01-27 17:36:19 +08:00
from .det_fce_loss import FCELoss
2022-10-17 16:47:28 +08:00
from .det_ct_loss import CTLoss
from .det_drrg_loss import DRRGLoss
2020-10-13 17:13:33 +08:00
2021-06-02 16:31:57 +08:00
# rec loss
from .rec_ctc_loss import CTCLoss
from .rec_att_loss import AttentionLoss
from .rec_srn_loss import SRNLoss
from .rec_ce_loss import CELoss
2021-08-24 11:49:26 +08:00
from .rec_sar_loss import SARLoss
2021-09-27 15:06:06 +08:00
from .rec_aster_loss import AsterLoss
from .rec_pren_loss import PRENLoss
from .rec_multi_loss import MultiLoss
from .rec_vl_loss import VLLoss
2022-06-12 13:53:29 +08:00
from .rec_spin_att_loss import SPINAttentionLoss
2022-10-17 16:47:28 +08:00
from .rec_rfl_loss import RFLLoss
2022-10-15 20:27:05 +08:00
from .rec_can_loss import CANLoss
from .rec_satrn_loss import SATRNLoss
from .rec_nrtr_loss import NRTRLoss
Add new recognition method "ParseQ" (#10836) * Update PP-OCRv4_introduction.md * Update PP-OCRv4_introduction.md (#10616) * Update PP-OCRv4_introduction.md * Update PP-OCRv4_introduction.md * Update PP-OCRv4_introduction.md * Update README.md * Cherrypicking GH-10217 and GH-10216 to PaddlePaddle:Release/2.7 (#10655) * Don't break overall processing on a bad image * Add preprocessing common to OCR tasks Add preprocessing to options * Update requirements.txt (#10656) added missing pyyaml library * [TIPC]update xpu tipc script (#10658) * fix-typo (#10642) Co-authored-by: Dennis <dvorst@users.noreply.github.com> Co-authored-by: shiyutang <34859558+shiyutang@users.noreply.github.com> * 修改数据增强导致的DSR报错 (#10662) (#10681) * 修改数据增强导致的DSR报错 * 错误修改回滚 * Update algorithm_overview_en.md (#10670) Fixed simple spelling errors. * Implement recoginition method ParseQ * Document update for new recognition method ParseQ * add prediction for parseq * Update rec_vit_parseq.yml * Update rec_r31_sar.yml * Update rec_r31_sar.yml * Update rec_r50_fpn_srn.yml * Update rec_vit_parseq.py * Update rec_vit_parseq.yml * Update rec_parseq_head.py * Update rec_img_aug.py * Update rec_vit_parseq.yml * Update __init__.py * Update predict_rec.py * Update paddleocr.py * Update requirements.txt * Update utility.py * Update utility.py --------- Co-authored-by: xiaoting <31891223+tink2123@users.noreply.github.com> Co-authored-by: topduke <784990967@qq.com> Co-authored-by: dyning <dyning.2003@163.com> Co-authored-by: UserUnknownFactor <63057995+UserUnknownFactor@users.noreply.github.com> Co-authored-by: itasli <ilyas.tasli@outlook.fr> Co-authored-by: Kai Song <50285351+USTCKAY@users.noreply.github.com> Co-authored-by: dvorst <87502756+dvorst@users.noreply.github.com> Co-authored-by: Dennis <dvorst@users.noreply.github.com> Co-authored-by: shiyutang <34859558+shiyutang@users.noreply.github.com> Co-authored-by: Dec20B <1192152456@qq.com> Co-authored-by: ncoffman <51147417+ncoffman@users.noreply.github.com>
2023-09-07 16:36:47 +08:00
from .rec_parseq_loss import ParseQLoss
from .rec_cppd_loss import CPPDLoss
from .rec_latexocr_loss import LaTeXOCRLoss
from .rec_unimernet_loss import UniMERNetLoss
from .rec_ppformulanet_loss import PPFormulaNet_S_Loss, PPFormulaNet_L_Loss
2021-09-27 15:06:06 +08:00
2021-06-02 16:31:57 +08:00
# cls loss
from .cls_loss import ClsLoss
# e2e loss
from .e2e_pg_loss import PGLoss
2021-10-09 17:53:22 +08:00
from .kie_sdmgr_loss import SDMGRLoss
2020-10-13 17:13:33 +08:00
2021-06-02 16:31:57 +08:00
# basic loss function
from .basic_loss import DistanceLoss
2020-10-13 17:13:33 +08:00
2021-06-02 16:31:57 +08:00
# combined loss function
from .combined_loss import CombinedLoss
2021-06-16 16:47:33 +08:00
# table loss
2022-08-10 22:58:08 +08:00
from .table_att_loss import TableAttentionLoss, SLALoss
2022-06-16 21:24:38 +08:00
from .table_master_loss import TableMasterLoss
# vqa token loss
from .vqa_token_layoutlm_loss import VQASerTokenLayoutLMLoss
# sr loss
from .stroke_focus_loss import StrokeFocusLoss
2022-10-17 15:15:37 +08:00
from .text_focus_loss import TelescopeLoss
2021-10-09 15:40:25 +08:00
2021-06-02 16:31:57 +08:00
def build_loss(config):
2021-01-29 11:15:03 +08:00
support_dict = [
"DBLoss",
"PSELoss",
"EASTLoss",
"SASTLoss",
"FCELoss",
"CTCLoss",
"ClsLoss",
"AttentionLoss",
"SRNLoss",
"PGLoss",
"CombinedLoss",
"CELoss",
"TableAttentionLoss",
"SARLoss",
"AsterLoss",
"SDMGRLoss",
"VQASerTokenLayoutLMLoss",
"LossFromOutput",
"PRENLoss",
"MultiLoss",
"TableMasterLoss",
"SPINAttentionLoss",
"VLLoss",
"StrokeFocusLoss",
"SLALoss",
"CTLoss",
"RFLLoss",
"DRRGLoss",
"CANLoss",
"TelescopeLoss",
"SATRNLoss",
"NRTRLoss",
"ParseQLoss",
"CPPDLoss",
"LaTeXOCRLoss",
"UniMERNetLoss",
"PPFormulaNet_S_Loss",
"PPFormulaNet_L_Loss",
2021-10-09 15:40:25 +08:00
]
2020-10-13 17:13:33 +08:00
config = copy.deepcopy(config)
module_name = config.pop("name")
assert module_name in support_dict, Exception(
"loss only support {}".format(support_dict)
)
2020-10-13 17:13:33 +08:00
module_class = eval(module_name)(**config)
return module_class