diff --git a/.gitignore b/.gitignore index 6dfdee420..4d50ce984 100644 --- a/.gitignore +++ b/.gitignore @@ -137,3 +137,6 @@ dmypy.json # mindspore compile related rank_*/ + +# DS_Store (MacOS) +.DS_Store diff --git a/deploy/py_infer/src/data_process/postprocess/det_db_postprocess.py b/deploy/py_infer/src/data_process/postprocess/det_db_postprocess.py index 0a46d7f4f..5f0549766 100644 --- a/deploy/py_infer/src/data_process/postprocess/det_db_postprocess.py +++ b/deploy/py_infer/src/data_process/postprocess/det_db_postprocess.py @@ -1,3 +1,20 @@ +# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. +# +# This code is adapted from https://github.com/PaddlePaddle/PaddleOCR +# with modifications to run on MindSpore. +# +# 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. + import logging import os import sys diff --git a/deploy/py_infer/src/data_process/postprocess/det_east_postprocess.py b/deploy/py_infer/src/data_process/postprocess/det_east_postprocess.py index 13b742cd7..f70a72ef7 100644 --- a/deploy/py_infer/src/data_process/postprocess/det_east_postprocess.py +++ b/deploy/py_infer/src/data_process/postprocess/det_east_postprocess.py @@ -1,3 +1,20 @@ +# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. +# +# This code is adapted from https://github.com/PaddlePaddle/PaddleOCR +# with modifications to run on MindSpore. +# +# 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. + import os import sys diff --git a/deploy/py_infer/src/data_process/postprocess/det_sast_postprocess.py b/deploy/py_infer/src/data_process/postprocess/det_sast_postprocess.py index 99e79d462..4e0f47eb3 100644 --- a/deploy/py_infer/src/data_process/postprocess/det_sast_postprocess.py +++ b/deploy/py_infer/src/data_process/postprocess/det_sast_postprocess.py @@ -1,3 +1,20 @@ +# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. +# +# This code is adapted from https://github.com/PaddlePaddle/PaddleOCR +# with modifications to run on MindSpore. +# +# 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. + import os import sys from typing import Tuple diff --git a/mindocr/data/layout_dataset.py b/mindocr/data/layout_dataset.py index 49fc72014..424f71d4f 100644 --- a/mindocr/data/layout_dataset.py +++ b/mindocr/data/layout_dataset.py @@ -1,3 +1,8 @@ +# This code is adapted from https://github.com/ultralytics/yolov5 +# with modifications to run on MindSpore. + +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + import glob import hashlib import json diff --git a/mindocr/data/transforms/rec_abinet_transforms.py b/mindocr/data/transforms/rec_abinet_transforms.py index 95a0ae386..f75769ce4 100644 --- a/mindocr/data/transforms/rec_abinet_transforms.py +++ b/mindocr/data/transforms/rec_abinet_transforms.py @@ -1,3 +1,6 @@ +# This code is adapted from https://github.com/FangShancheng/ABINet +# with modifications to run on MindSpore. + """ transform for text recognition tasks. """ diff --git a/mindocr/data/transforms/rec_transforms.py b/mindocr/data/transforms/rec_transforms.py index f0db1485f..fa1e95727 100644 --- a/mindocr/data/transforms/rec_transforms.py +++ b/mindocr/data/transforms/rec_transforms.py @@ -1,3 +1,19 @@ +# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. +# +# This code is adapted from https://github.com/PaddlePaddle/PaddleOCR +# with modifications to run on MindSpore. +# +# 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. """ transform for text recognition tasks. """ diff --git a/mindocr/data/transforms/svtr_transform.py b/mindocr/data/transforms/svtr_transform.py index 4281c5261..1e294eed8 100644 --- a/mindocr/data/transforms/svtr_transform.py +++ b/mindocr/data/transforms/svtr_transform.py @@ -1,3 +1,19 @@ +# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. +# +# This code is adapted from https://github.com/PaddlePaddle/PaddleOCR +# with modifications to run on MindSpore. +# +# 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. import copy import logging import math diff --git a/mindocr/data/transforms/table_transform.py b/mindocr/data/transforms/table_transform.py index 78fea3461..1f9a7569f 100644 --- a/mindocr/data/transforms/table_transform.py +++ b/mindocr/data/transforms/table_transform.py @@ -1,3 +1,20 @@ +# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. +# +# This code is adapted from https://github.com/PaddlePaddle/PaddleOCR +# with modifications to run on MindSpore. +# +# 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. + import logging import cv2 diff --git a/mindocr/models/backbones/blocks/magca.py b/mindocr/models/backbones/blocks/magca.py index 7e51f5ca9..1650a5eab 100644 --- a/mindocr/models/backbones/blocks/magca.py +++ b/mindocr/models/backbones/blocks/magca.py @@ -1,3 +1,6 @@ +# This code is adapted from https://github.com/JiaquanYe/TableMASTER-mmocr +# with modifications to run on MindSpore. + import mindspore.nn as nn import mindspore.ops as ops from mindspore import Tensor diff --git a/mindocr/models/backbones/layoutlmv3/layoutlmv3.py b/mindocr/models/backbones/layoutlmv3/layoutlmv3.py index 1a1f52516..caea52da9 100644 --- a/mindocr/models/backbones/layoutlmv3/layoutlmv3.py +++ b/mindocr/models/backbones/layoutlmv3/layoutlmv3.py @@ -637,6 +637,8 @@ def construct( return (sequence_output,) + encoder_outputs[1:] +# This code is adapted from +# https://github.com/facebookresearch/detectron2/blob/main/detectron2/modeling/backbone/fpn.py class FPNForLayout(FPN): def __init__(self, bottom_up, diff --git a/mindocr/models/backbones/layoutxlm/configuration.py b/mindocr/models/backbones/layoutxlm/configuration.py index ece3b3b7b..e0741c331 100644 --- a/mindocr/models/backbones/layoutxlm/configuration.py +++ b/mindocr/models/backbones/layoutxlm/configuration.py @@ -1,3 +1,20 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# This code is adapted from https://github.com/PaddlePaddle/PaddleNLP +# with modifications to run on MindSpore. +# +# 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. + from dataclasses import dataclass diff --git a/mindocr/models/backbones/layoutxlm/resnet.py b/mindocr/models/backbones/layoutxlm/resnet.py index e4ca7cd56..19a5b8431 100644 --- a/mindocr/models/backbones/layoutxlm/resnet.py +++ b/mindocr/models/backbones/layoutxlm/resnet.py @@ -1,3 +1,8 @@ +# This code is adapted from https://github.com/facebookresearch/detectron2 +# with modifications to run on MindSpore. + +# Copyright (c) Facebook, Inc. and its affiliates. + from dataclasses import dataclass from typing import Optional diff --git a/mindocr/models/backbones/layoutxlm/tokenizer.py b/mindocr/models/backbones/layoutxlm/tokenizer.py index 739e05eee..db7868dbc 100644 --- a/mindocr/models/backbones/layoutxlm/tokenizer.py +++ b/mindocr/models/backbones/layoutxlm/tokenizer.py @@ -1,3 +1,21 @@ +# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. +# +# This code is adapted from https://github.com/PaddlePaddle/PaddleNLP +# with modifications to run on MindSpore. +# +# 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. + from typing import List, Optional import sentencepiece as spm diff --git a/mindocr/models/backbones/layoutxlm/tokenizer_utils.py b/mindocr/models/backbones/layoutxlm/tokenizer_utils.py index d1eb9cb02..d41496add 100644 --- a/mindocr/models/backbones/layoutxlm/tokenizer_utils.py +++ b/mindocr/models/backbones/layoutxlm/tokenizer_utils.py @@ -1,3 +1,22 @@ +# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. +# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. +# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. +# +# This code is adapted from https://github.com/PaddlePaddle/PaddleNLP +# with modifications to run on MindSpore. +# +# 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. + import bisect import io import itertools diff --git a/mindocr/models/backbones/layoutxlm/tokenizer_utils_base.py b/mindocr/models/backbones/layoutxlm/tokenizer_utils_base.py index b4870bf70..4945ce10f 100644 --- a/mindocr/models/backbones/layoutxlm/tokenizer_utils_base.py +++ b/mindocr/models/backbones/layoutxlm/tokenizer_utils_base.py @@ -1,3 +1,22 @@ +# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. +# Copyright (c) 2018, NVIDIA CORPORATION. All Rights Reserved. +# Copyright (c) 2020, PaddlePaddle Authors. All Rights Reserved. +# +# This code is adapted from https://github.com/PaddlePaddle/PaddleNLP +# with modifications to run on MindSpore. +# +# 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. + import copy import io import json diff --git a/mindocr/models/backbones/layoutxlm/utils.py b/mindocr/models/backbones/layoutxlm/utils.py index 54bff0364..a141dbe99 100644 --- a/mindocr/models/backbones/layoutxlm/utils.py +++ b/mindocr/models/backbones/layoutxlm/utils.py @@ -1,3 +1,20 @@ +# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. +# +# This code is adapted from https://github.com/PaddlePaddle/PaddleNLP +# with modifications to run on MindSpore. +# +# 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. + import functools import inspect import os diff --git a/mindocr/models/backbones/layoutxlm/visual_backbone.py b/mindocr/models/backbones/layoutxlm/visual_backbone.py index 4155c6212..f3b1f7d10 100644 --- a/mindocr/models/backbones/layoutxlm/visual_backbone.py +++ b/mindocr/models/backbones/layoutxlm/visual_backbone.py @@ -1,3 +1,8 @@ +# This code is adapted from https://github.com/facebookresearch/detectron2 +# with modifications to run on MindSpore. + +# Copyright (c) Facebook, Inc. and its affiliates. + import math import os diff --git a/mindocr/models/backbones/layoutxlm/vocab.py b/mindocr/models/backbones/layoutxlm/vocab.py index 02c6b7958..5809d77a9 100644 --- a/mindocr/models/backbones/layoutxlm/vocab.py +++ b/mindocr/models/backbones/layoutxlm/vocab.py @@ -1,3 +1,20 @@ +# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. +# +# This code is adapted from https://github.com/PaddlePaddle/PaddleNLP +# with modifications to run on MindSpore. +# +# 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. + import collections import io import json diff --git a/mindocr/models/backbones/mindcv_models/coat.py b/mindocr/models/backbones/mindcv_models/coat.py index 0980c808e..b841f15db 100644 --- a/mindocr/models/backbones/mindcv_models/coat.py +++ b/mindocr/models/backbones/mindcv_models/coat.py @@ -1,5 +1,12 @@ +# This code is adapted from https://github.com/huggingface/pytorch-image-models +# with modifications to run on MindSpore. """ CoaT architecture. + +Paper: Co-Scale Conv-Attentional Image Transformers - https://arxiv.org/abs/2104.06399 + +Official CoaT code at: https://github.com/mlpc-ucsd/CoaT + Modified from timm/models/vision_transformer.py """ from typing import Union diff --git a/mindocr/models/backbones/mindcv_models/crossvit.py b/mindocr/models/backbones/mindcv_models/crossvit.py index 5b9b156a6..5f3f5d31f 100644 --- a/mindocr/models/backbones/mindcv_models/crossvit.py +++ b/mindocr/models/backbones/mindcv_models/crossvit.py @@ -1,7 +1,27 @@ +# This code is adapted from https://github.com/huggingface/pytorch-image-models +# with modifications to run on MindSpore. + +""" CrossViT Model + +@inproceedings{ + chen2021crossvit, + title={{CrossViT: Cross-Attention Multi-Scale Vision Transformer for Image Classification}}, + author={Chun-Fu (Richard) Chen and Quanfu Fan and Rameswar Panda}, + booktitle={International Conference on Computer Vision (ICCV)}, + year={2021} +} + +Paper link: https://arxiv.org/abs/2103.14899 +Original code: https://github.com/IBM/CrossViT/blob/main/models/crossvit.py + +NOTE: model names have been renamed from originals to represent actual input res all *_224 -> *_240 and *_384 -> *_408 + +Modifications and additions for timm hacked together by / Copyright 2021, Ross Wightman +Modified from Timm. https://github.com/rwightman/pytorch-image-models/blob/master/timm/models/vision_transformer.py """ -MindSpore implementation of `crossvit`. -Refer to crossvit: Cross-Attention Multi-Scale Vision Transformer for Image Classification -""" + +# Copyright IBM All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 import numpy as np diff --git a/mindocr/models/backbones/mindcv_models/densenet.py b/mindocr/models/backbones/mindcv_models/densenet.py index 51e1d705d..e5c63a7a5 100644 --- a/mindocr/models/backbones/mindcv_models/densenet.py +++ b/mindocr/models/backbones/mindcv_models/densenet.py @@ -1,6 +1,9 @@ -""" -MindSpore implementation of `DenseNet`. -Refer to: Densely Connected Convolutional Networks +# This code is adapted from https://github.com/huggingface/pytorch-image-models +# with modifications to run on MindSpore. + +"""Pytorch Densenet implementation w/ tweaks +This file is a copy of https://github.com/pytorch/vision 'densenet.py' (BSD-3-Clause) with +fixed kwargs passthrough and addition of dynamic global avg/max pool. """ import math diff --git a/mindocr/models/backbones/mindcv_models/efficientnet.py b/mindocr/models/backbones/mindcv_models/efficientnet.py index 3216d3d19..83c21d33e 100644 --- a/mindocr/models/backbones/mindcv_models/efficientnet.py +++ b/mindocr/models/backbones/mindcv_models/efficientnet.py @@ -1,4 +1,43 @@ -"""EfficientNet Architecture.""" +# This code is adapted from https://github.com/huggingface/pytorch-image-models +# with modifications to run on MindSpore. + +""" The EfficientNet Family in PyTorch + +An implementation of EfficienNet that covers variety of related models with efficient architectures: + +* EfficientNet-V2 + - `EfficientNetV2: Smaller Models and Faster Training` - https://arxiv.org/abs/2104.00298 + +* EfficientNet (B0-B8, L2 + Tensorflow pretrained AutoAug/RandAug/AdvProp/NoisyStudent weight ports) + - EfficientNet: Rethinking Model Scaling for CNNs - https://arxiv.org/abs/1905.11946 + - CondConv: Conditionally Parameterized Convolutions for Efficient Inference - https://arxiv.org/abs/1904.04971 + - Adversarial Examples Improve Image Recognition - https://arxiv.org/abs/1911.09665 + - Self-training with Noisy Student improves ImageNet classification - https://arxiv.org/abs/1911.04252 + +* MixNet (Small, Medium, and Large) + - MixConv: Mixed Depthwise Convolutional Kernels - https://arxiv.org/abs/1907.09595 + +* MNasNet B1, A1 (SE), Small + - MnasNet: Platform-Aware Neural Architecture Search for Mobile - https://arxiv.org/abs/1807.11626 + +* FBNet-C + - FBNet: Hardware-Aware Efficient ConvNet Design via Differentiable NAS - https://arxiv.org/abs/1812.03443 + +* Single-Path NAS Pixel1 + - Single-Path NAS: Designing Hardware-Efficient ConvNets - https://arxiv.org/abs/1904.02877 + +* TinyNet + - Model Rubik's Cube: Twisting Resolution, Depth and Width for TinyNets - https://arxiv.org/abs/2010.14819 + - Definitions & weights borrowed from https://github.com/huawei-noah/CV-Backbones/tree/master/tinynet_pytorch + +* And likely more... + +The majority of the above models (EfficientNet*, MixNet, MnasNet) and original weights were made available +by Mingxing Tan, Quoc Le, and other members of their Google Brain team. Thanks for consistently releasing +the models and weights open source! + +Hacked together by / Copyright 2019, Ross Wightman +""" import copy import math diff --git a/mindocr/models/backbones/mindcv_models/ghostnet.py b/mindocr/models/backbones/mindcv_models/ghostnet.py index e69f88b29..de43f6e47 100644 --- a/mindocr/models/backbones/mindcv_models/ghostnet.py +++ b/mindocr/models/backbones/mindcv_models/ghostnet.py @@ -1,4 +1,21 @@ -"""MindSpore implementation of `GhostNet`.""" +# This code is adapted from https://github.com/huggingface/pytorch-image-models +# with modifications to run on MindSpore. + +""" +An implementation of GhostNet & GhostNetV2 Models as defined in: +GhostNet: More Features from Cheap Operations. https://arxiv.org/abs/1911.11907 +GhostNetV2: Enhance Cheap Operation with Long-Range Attention. +https://proceedings.neurips.cc/paper_files/paper/2022/file/40b60852a4abdaa696b5a1a78da34635-Paper-Conference.pdf +GhostNetV3: Exploring the Training Strategies for Compact Models. https://arxiv.org/abs/2404.11202 + +The train script & code of models at: +Original model: +https://github.com/huawei-noah/CV-backbones/tree/master/ghostnet_pytorch +Original model: +https://github.com/huawei-noah/Efficient-AI-Backbones/blob/master/ghostnetv2_pytorch/model/ghostnetv2_torch.py +Original model: +https://github.com/huawei-noah/Efficient-AI-Backbones/blob/master/ghostnetv3_pytorch/ghostnetv3.py +""" import math diff --git a/mindocr/models/backbones/mindcv_models/hrnet.py b/mindocr/models/backbones/mindcv_models/hrnet.py index 97d882672..a71051860 100644 --- a/mindocr/models/backbones/mindcv_models/hrnet.py +++ b/mindocr/models/backbones/mindcv_models/hrnet.py @@ -1,6 +1,14 @@ -""" -MindSpore implementation of `HRNet`. -Refer to Deep High-Resolution Representation Learning for Visual Recognition +# This code is adapted from https://github.com/huggingface/pytorch-image-models +# with modifications to run on MindSpore. +""" HRNet + +Copied from https://github.com/HRNet/HRNet-Image-Classification + +Original header: + Copyright (c) Microsoft + Licensed under the MIT License. + Written by Bin Xiao (Bin.Xiao@microsoft.com) + Modified by Ke Sun (sunk@mail.ustc.edu.cn) """ from typing import Any, Dict, List, Optional, Tuple, Type, Union diff --git a/mindocr/models/backbones/mindcv_models/layers/selective_kernel.py b/mindocr/models/backbones/mindcv_models/layers/selective_kernel.py index 3dcc1409a..19e180564 100644 --- a/mindocr/models/backbones/mindcv_models/layers/selective_kernel.py +++ b/mindocr/models/backbones/mindcv_models/layers/selective_kernel.py @@ -1,5 +1,10 @@ +# This code is adapted from https://github.com/huggingface/pytorch-image-models +# with modifications to run on MindSpore. """ Selective Kernel Convolution/Attention + Paper: Selective Kernel Networks (https://arxiv.org/abs/1903.06586) + +Hacked together by / Copyright 2020 Ross Wightman """ from typing import List, Optional, Union diff --git a/mindocr/models/backbones/mindcv_models/pit.py b/mindocr/models/backbones/mindcv_models/pit.py index 91c255f82..a10df1f4a 100644 --- a/mindocr/models/backbones/mindcv_models/pit.py +++ b/mindocr/models/backbones/mindcv_models/pit.py @@ -1,7 +1,18 @@ +# This code is adapted from https://github.com/huggingface/pytorch-image-models +# with modifications to run on MindSpore. + +""" Pooling-based Vision Transformer (PiT) in MindSpore + +A MindSpore implement of Pooling-based Vision Transformers as described in +'Rethinking Spatial Dimensions of Vision Transformers' - https://arxiv.org/abs/2103.16302 + +This code was adapted from the original version at https://github.com/naver-ai/pit, original copyright below. + +Modifications for timm by / Copyright 2020 Ross Wightman """ -MindSpore implementation of `PiT`. -Refer to Rethinking Spatial Dimensions of Vision Transformers. -""" +# PiT +# Copyright 2021-present NAVER Corp. +# Apache License v2.0 import math from typing import List diff --git a/mindocr/models/backbones/mindcv_models/pnasnet.py b/mindocr/models/backbones/mindcv_models/pnasnet.py index 651b567b4..d3a5d653f 100644 --- a/mindocr/models/backbones/mindcv_models/pnasnet.py +++ b/mindocr/models/backbones/mindcv_models/pnasnet.py @@ -1,6 +1,12 @@ +# This code is adapted from https://github.com/huggingface/pytorch-image-models +# with modifications to run on MindSpore. + """ -MindSpore implementation of pnasnet. -Refer to Progressive Neural Architecture Search. + pnasnet5large implementation grabbed from Cadene's pretrained models + Additional credit to https://github.com/creafz + + https://github.com/Cadene/pretrained-models.pytorch/blob/master/pretrainedmodels/models/pnasnet.py + """ import math diff --git a/mindocr/models/backbones/mindcv_models/poolformer.py b/mindocr/models/backbones/mindcv_models/poolformer.py index b61c623a4..b135dace8 100644 --- a/mindocr/models/backbones/mindcv_models/poolformer.py +++ b/mindocr/models/backbones/mindcv_models/poolformer.py @@ -1,7 +1,27 @@ +# This code is adapted from https://github.com/huggingface/pytorch-image-models +# with modifications to run on MindSpore. + +""" PoolFormer implementation + +Paper: `PoolFormer: MetaFormer is Actually What You Need for Vision` - https://arxiv.org/abs/2111.11418 + +Code adapted from official impl at https://github.com/sail-sg/poolformer, original copyright in comment below + +Modifications and additions for timm by / Copyright 2022, Ross Wightman """ -MindSpore implementation of `poolformer`. -Refer to PoolFormer: MetaFormer Is Actually What You Need for Vision. -""" +# Copyright 2021 Garena Online Private Limited +# +# 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. import collections.abc from itertools import repeat diff --git a/mindocr/models/backbones/mindcv_models/pvtv2.py b/mindocr/models/backbones/mindcv_models/pvtv2.py index c2f621cb6..96d56f817 100644 --- a/mindocr/models/backbones/mindcv_models/pvtv2.py +++ b/mindocr/models/backbones/mindcv_models/pvtv2.py @@ -1,6 +1,21 @@ -""" -MindSpore implementation of `PVTv2`. -Refer to PVTv2: PVTv2: Improved Baselines with Pyramid Vision Transformer +# This code is adapted from https://github.com/huggingface/pytorch-image-models +# with modifications to run on MindSpore. + +""" Pyramid Vision Transformer v2 + +@misc{wang2021pvtv2, + title={PVTv2: Improved Baselines with Pyramid Vision Transformer}, + author={Wenhai Wang and Enze Xie and Xiang Li and Deng-Ping Fan and Kaitao Song and Ding Liang and + Tong Lu and Ping Luo and Ling Shao}, + year={2021}, + eprint={2106.13797}, + archivePrefix={arXiv}, + primaryClass={cs.CV} +} + +Based on Apache 2.0 licensed code at https://github.com/whai362/PVT + +Modifications and timm support by / Copyright 2022, Ross Wightman """ import math from functools import partial diff --git a/mindocr/models/backbones/mindcv_models/registry.py b/mindocr/models/backbones/mindcv_models/registry.py index d4e3018ba..5d502db6e 100644 --- a/mindocr/models/backbones/mindcv_models/registry.py +++ b/mindocr/models/backbones/mindcv_models/registry.py @@ -1,4 +1,9 @@ -"""model registry and list""" +# This code is adapted from https://github.com/huggingface/pytorch-image-models +# with modifications to run on MindSpore. +""" Model Registry +Hacked together by / Copyright 2020 Ross Wightman +""" + import fnmatch import sys from collections import defaultdict diff --git a/mindocr/models/backbones/mindcv_models/resnest.py b/mindocr/models/backbones/mindcv_models/resnest.py index a07344598..2cc172885 100644 --- a/mindocr/models/backbones/mindcv_models/resnest.py +++ b/mindocr/models/backbones/mindcv_models/resnest.py @@ -1,6 +1,13 @@ -""" -MindSpore implementation of `ResNeSt`. -Refer to ResNeSt: Split-Attention Networks. +# This code is adapted from https://github.com/huggingface/pytorch-image-models +# with modifications to run on MindSpore. + +""" ResNeSt Models + +Paper: `ResNeSt: Split-Attention Networks` - https://arxiv.org/abs/2004.08955 + +Adapted from original PyTorch impl w/ weights at https://github.com/zhanghang1989/ResNeSt by Hang Zhang + +Modified for torchscript compat, and consistency with timm by Ross Wightman """ from typing import List, Optional, Type diff --git a/mindocr/models/backbones/mindcv_models/senet.py b/mindocr/models/backbones/mindcv_models/senet.py index 8ccc69ade..64be110ba 100644 --- a/mindocr/models/backbones/mindcv_models/senet.py +++ b/mindocr/models/backbones/mindcv_models/senet.py @@ -1,6 +1,17 @@ +# This code is adapted from https://github.com/huggingface/pytorch-image-models +# with modifications to run on MindSpore. """ -MindSpore implementation of `SENet`. -Refer to Squeeze-and-Excitation Networks. +SEResNet implementation from Cadene's pretrained models +https://github.com/Cadene/pretrained-models.pytorch/blob/master/pretrainedmodels/models/senet.py +Additional credit to https://github.com/creafz + +Original model: https://github.com/hujie-frank/SENet + +ResNet code gently borrowed from +https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py + +FIXME I'm deprecating this model and moving them to ResNet as I don't want to maintain duplicate +support for extras like dilation, switchable BN/activations, feature extraction, etc that don't exist here. """ import math diff --git a/mindocr/models/backbones/mindcv_models/xception.py b/mindocr/models/backbones/mindcv_models/xception.py index 6fd1b953d..b6099cedb 100644 --- a/mindocr/models/backbones/mindcv_models/xception.py +++ b/mindocr/models/backbones/mindcv_models/xception.py @@ -1,6 +1,27 @@ +# This code is adapted from https://github.com/huggingface/pytorch-image-models +# with modifications to run on MindSpore. """ -MindSpore implementation of Xception. -Refer to Xception: Deep Learning with Depthwise Separable Convolutions. +Ported to MindSpore thanks to [tstandley](https://github.com/tstandley/Xception-PyTorch) + +@author: tstandley +Adapted by cadene + +Creates an Xception Model as defined in: + +Francois Chollet +Xception: Deep Learning with Depthwise Separable Convolutions +https://arxiv.org/pdf/1610.02357.pdf + +This weights ported from the Keras implementation. Achieves the following performance on the validation set: + +Loss:0.9173 Prec@1:78.892 Prec@5:94.292 + +REMEMBER to set your image size to 3x299x299 for both test and validation + +normalize = transforms.Normalize(mean=[0.5, 0.5, 0.5], + std=[0.5, 0.5, 0.5]) + +The resize parameter of the validation transform should be 333, and make sure to center crop at 299x299 """ import mindspore.common.initializer as init diff --git a/mindocr/models/backbones/mindcv_models/xcit.py b/mindocr/models/backbones/mindcv_models/xcit.py index 8d2d4b363..527be45ad 100644 --- a/mindocr/models/backbones/mindcv_models/xcit.py +++ b/mindocr/models/backbones/mindcv_models/xcit.py @@ -1,7 +1,18 @@ +# This code is adapted from https://github.com/huggingface/pytorch-image-models +# with modifications to run on MindSpore. + +""" Cross-Covariance Image Transformer (XCiT) in MindSpore + +Paper: + - https://arxiv.org/abs/2106.09681 + +Same as the official implementation, with some minor adaptations, original copyright below + - https://github.com/facebookresearch/xcit/blob/master/xcit.py + +Modifications and additions for timm hacked together by / Copyright 2021, Ross Wightman """ -MindSpore implementation of XCiT -Refer to: XCiT: Cross-Covariance Image Transformers -""" +# Copyright (c) 2015-present, Facebook, Inc. +# All rights reserved. from functools import partial import numpy as np diff --git a/mindocr/models/backbones/rec_resnet.py b/mindocr/models/backbones/rec_resnet.py index f2ed29418..074522a66 100644 --- a/mindocr/models/backbones/rec_resnet.py +++ b/mindocr/models/backbones/rec_resnet.py @@ -1,3 +1,25 @@ +# copyright (c) 2021 PaddlePaddle Authors. All Rights Reserve. +# +# This code is adapted from https://github.com/PaddlePaddle/PaddleOCR +# with modifications to run on MindSpore. +# +# 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. +""" +This code is refer from: +https://github.com/open-mmlab/mmocr/blob/main/mmocr/models/textrecog/layers/conv_layer.py +https://github.com/open-mmlab/mmocr/blob/main/mmocr/models/textrecog/backbones/resnet31_ocr.py +""" + from mindspore import nn from ._registry import register_backbone, register_backbone_class diff --git a/mindocr/models/backbones/rec_svtr_enhance.py b/mindocr/models/backbones/rec_svtr_enhance.py index 418275ea7..c24fb6a12 100644 --- a/mindocr/models/backbones/rec_svtr_enhance.py +++ b/mindocr/models/backbones/rec_svtr_enhance.py @@ -1,3 +1,24 @@ +# copyright (c) 2021 PaddlePaddle Authors. All Rights Reserve. +# +# This code is adapted from https://github.com/PaddlePaddle/PaddleOCR +# with modifications to run on MindSpore. +# +# 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. + +# This code is refer from: +# https://github.com/PaddlePaddle/PaddleClas/blob/develop/ppcls/arch/backbone/legendary_models/pp_lcnet.py + + from mindspore import nn from ..utils.attention_cells import SEModule diff --git a/mindocr/models/backbones/transformer_common/layer.py b/mindocr/models/backbones/transformer_common/layer.py index 1ebc25c97..f2e441e73 100644 --- a/mindocr/models/backbones/transformer_common/layer.py +++ b/mindocr/models/backbones/transformer_common/layer.py @@ -1,3 +1,21 @@ +# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +# Copyright 2021 Microsoft Research and The HuggingFace Inc. team. All rights reserved. +# +# This code is adapted from https://github.com/PaddlePaddle/PaddleOCR +# with modifications to run on MindSpore. +# +# 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. + import math import numpy as np diff --git a/mindocr/nlp/generation/beam_search.py b/mindocr/nlp/generation/beam_search.py index a5c931156..851377c34 100644 --- a/mindocr/nlp/generation/beam_search.py +++ b/mindocr/nlp/generation/beam_search.py @@ -1,3 +1,21 @@ +# Copyright 2020 The HuggingFace Team Inc. +# +# This code is adapted from https://github.com/huggingface/transformers +# with modifications to run on MindSpore. +# +# 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 clone 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. + + """Beam search for text generation.""" from abc import ABC, abstractmethod from collections import UserDict diff --git a/mindocr/nlp/llm/qwen_tokenizer.py b/mindocr/nlp/llm/qwen_tokenizer.py index 8ad4224d2..9434b3b7f 100644 --- a/mindocr/nlp/llm/qwen_tokenizer.py +++ b/mindocr/nlp/llm/qwen_tokenizer.py @@ -1,3 +1,20 @@ +# Copyright 2020 The HuggingFace Inc. team. +# +# This code is adapted from https://github.com/huggingface/transformers +# with modifications to run on MindSpore. +# +# 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. + import base64 import unicodedata from typing import Collection, Dict, List, Set, Union diff --git a/mindocr/postprocess/det_db_postprocess.py b/mindocr/postprocess/det_db_postprocess.py index 6e10c787e..8d8763677 100644 --- a/mindocr/postprocess/det_db_postprocess.py +++ b/mindocr/postprocess/det_db_postprocess.py @@ -1,3 +1,6 @@ +# This code is adapted from https://github.com/WenmuZhou/DBNet.pytorch +# with modifications to run on MindSpore. + from typing import List, Tuple, Union import cv2 diff --git a/mindocr/postprocess/det_east_postprocess.py b/mindocr/postprocess/det_east_postprocess.py index 7b08bc5e3..53d112e03 100644 --- a/mindocr/postprocess/det_east_postprocess.py +++ b/mindocr/postprocess/det_east_postprocess.py @@ -1,3 +1,6 @@ +# This code is adapted from https://github.com/sakurariven/east +# with modifications to run on MindSpore. + import math import numpy as np diff --git a/mindocr/postprocess/det_pse_postprocess.py b/mindocr/postprocess/det_pse_postprocess.py index ec8397256..5ec120b88 100644 --- a/mindocr/postprocess/det_pse_postprocess.py +++ b/mindocr/postprocess/det_pse_postprocess.py @@ -1,3 +1,6 @@ +# This code is adapted from https://github.com/whai362/PSENet +# with modifications to run on MindSpore. + import cv2 import numpy as np diff --git a/mindocr/postprocess/kie_ser_postprocess.py b/mindocr/postprocess/kie_ser_postprocess.py index 04bf86c6f..9e51691c8 100644 --- a/mindocr/postprocess/kie_ser_postprocess.py +++ b/mindocr/postprocess/kie_ser_postprocess.py @@ -1,3 +1,20 @@ +# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +# +# This code is adapted from https://github.com/PaddlePaddle/PaddleOCR +# with modifications to run on MindSpore. +# +# 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. + import numpy as np import mindspore as ms diff --git a/mindocr/postprocess/pse/pse.pyx b/mindocr/postprocess/pse/pse.pyx index 8b7c4fd58..87a39d8c8 100644 --- a/mindocr/postprocess/pse/pse.pyx +++ b/mindocr/postprocess/pse/pse.pyx @@ -1,3 +1,4 @@ +# This code is adapted from https://github.com/PaddlePaddle/PaddleOCR import cv2 import numpy as np diff --git a/mindocr/postprocess/rec_postprocess.py b/mindocr/postprocess/rec_postprocess.py index 1569074df..dcf05c679 100644 --- a/mindocr/postprocess/rec_postprocess.py +++ b/mindocr/postprocess/rec_postprocess.py @@ -1,5 +1,19 @@ -""" -""" +# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. +# +# This code is adapted from https://github.com/PaddlePaddle/PaddleOCR +# with modifications to run on MindSpore. +# +# 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. import logging import re from typing import Any, Dict, List, Optional, Tuple, Union diff --git a/mindocr/postprocess/table_postprocess.py b/mindocr/postprocess/table_postprocess.py index 6131d3206..f9bc7ffe1 100644 --- a/mindocr/postprocess/table_postprocess.py +++ b/mindocr/postprocess/table_postprocess.py @@ -1,3 +1,20 @@ +# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +# +# This code is adapted from https://github.com/PaddlePaddle/PaddleOCR +# with modifications to run on MindSpore. +# +# 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. + import re import numpy as np diff --git a/mindocr/utils/visualize.py b/mindocr/utils/visualize.py index 3db18bb1e..bcf4eabe1 100644 --- a/mindocr/utils/visualize.py +++ b/mindocr/utils/visualize.py @@ -1,3 +1,20 @@ +# copyright (c) 2021 PaddlePaddle Authors. All Rights Reserve. +# +# This code is adapted from https://github.com/PaddlePaddle/PaddleOCR +# with modifications to run on MindSpore. +# +# 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. + import logging import math import os diff --git a/tools/infer/text/utils/matcher.py b/tools/infer/text/utils/matcher.py index 41a77470f..fe13df173 100644 --- a/tools/infer/text/utils/matcher.py +++ b/tools/infer/text/utils/matcher.py @@ -1,3 +1,5 @@ +# This code is adapted from https://github.com/JiaquanYe/TableMaster-mmocr + import copy import glob import math diff --git a/tools/infer/text/utils/table_process.py b/tools/infer/text/utils/table_process.py index 045a0bb10..23f57221b 100644 --- a/tools/infer/text/utils/table_process.py +++ b/tools/infer/text/utils/table_process.py @@ -1,3 +1,22 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# This code is adapted from https://github.com/PaddlePaddle/PaddleOCR +# +# 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. +""" +This code is refer from: https://github.com/weizwx/html2docx/blob/master/htmldocx/h2d.py +""" + import re from html.parser import HTMLParser