Skip to content

Commit 0904366

Browse files
authored
add ConvNext & ConvNextv2 (#1201)
1 parent 15fa614 commit 0904366

File tree

16 files changed

+1771
-1
lines changed

16 files changed

+1771
-1
lines changed

mindone/transformers/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,20 @@
255255
ConvBertLayer,
256256
ConvBertModel,
257257
)
258+
from .models.convnext import (
259+
ConvNextBackbone,
260+
ConvNextFeatureExtractor,
261+
ConvNextForImageClassification,
262+
ConvNextImageProcessor,
263+
ConvNextModel,
264+
ConvNextPreTrainedModel,
265+
)
266+
from .models.convnextv2 import (
267+
ConvNextV2Backbone,
268+
ConvNextV2ForImageClassification,
269+
ConvNextV2Model,
270+
ConvNextV2PreTrainedModel,
271+
)
258272
from .models.deberta import (
259273
DebertaForMaskedLM,
260274
DebertaForQuestionAnswering,

mindone/transformers/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
clap,
3535
clip,
3636
convbert,
37+
convnext,
38+
convnextv2,
3739
depth_anything,
3840
dinov2,
3941
dpt,

mindone/transformers/models/auto/configuration_auto.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
("chameleon", "ChameleonConfig"),
4747
("camembert", "CamembertConfig"),
4848
("convbert", "ConvBertConfig"),
49+
("convnext", "ConvNextConfig"),
50+
("convnextv2", "ConvNextV2Config"),
4951
("clip", "CLIPConfig"),
5052
("clip_vision_model", "CLIPVisionConfig"),
5153
("deberta", "DebertaConfig"),
@@ -143,6 +145,8 @@
143145
("clip", "CLIP"),
144146
("starcoder2", "Starcoder2"),
145147
("clip_vision_model", "CLIPVisionModel"),
148+
("convnext", "ConvNeXT"),
149+
("convnextv2", "ConvNeXTV2"),
146150
("deberta", "DeBERTa"),
147151
("deberta-v2", "DeBERTa-v2"),
148152
("depth_anything", "Depth Anything"),

mindone/transformers/models/auto/feature_extraction_auto.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@
4141

4242
logger = logging.get_logger(__name__)
4343

44-
FEATURE_EXTRACTOR_MAPPING_NAMES = OrderedDict()
44+
FEATURE_EXTRACTOR_MAPPING_NAMES = OrderedDict(
45+
[
46+
("convnext", "ConvNextFeatureExtractor"),
47+
]
48+
)
4549

4650
FEATURE_EXTRACTOR_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, FEATURE_EXTRACTOR_MAPPING_NAMES)
4751

mindone/transformers/models/auto/image_processing_auto.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
("blip-2", ("BlipImageProcessor",)),
5353
("chameleon", ("ChameleonImageProcessor",)),
5454
("clip", ("CLIPImageProcessor",)),
55+
("convnext", ("ConvNextImageProcessor",)),
56+
("convnextv2", ("ConvNextImageProcessor",)),
5557
("depth_anything", ("DPTImageProcessor",)),
5658
("dinov2", ("BitImageProcessor",)),
5759
("dpt", ("DPTImageProcessor",)),

mindone/transformers/models/auto/modeling_auto.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
("clip", "CLIPModel"),
5151
("clip_text_model", "CLIPTextModel"),
5252
("clip_vision_model", "CLIPVisionModel"),
53+
("convnext", "ConvNextModel"),
54+
("convnextv2", "ConvNextV2Model"),
5355
("deberta", "DebertaModel"),
5456
("opt", "OPTModel"),
5557
("deberta-v2", "DebertaV2Model"),
@@ -219,6 +221,8 @@
219221
[
220222
# Model for Image mapping
221223
("bit", "BitModel"),
224+
("convnext", "ConvNextModel"),
225+
("convnextv2", "ConvNextV2Model"),
222226
("detr", "DetrModel"),
223227
("dinov2", "Dinov2Model"),
224228
("dpt", "DPTModel"),
@@ -252,6 +256,8 @@
252256
# Model for Image Classification mapping
253257
("bit", "BitForImageClassification"),
254258
("clip", "CLIPForImageClassification"),
259+
("convnext", "ConvNextForImageClassification"),
260+
("convnextv2", "ConvNextV2ForImageClassification"),
255261
("dinov2", "Dinov2ForImageClassification"),
256262
("hiera", "HieraForImageClassification"),
257263
("ijepa", "IJepaForImageClassification"),
@@ -601,6 +607,8 @@
601607

602608
MODEL_FOR_BACKBONE_MAPPING_NAMES = OrderedDict(
603609
[
610+
("convnext", "ConvNextBackbone"),
611+
("convnextv2", "ConvNextV2Backbone"),
604612
("dinov2", "Dinov2Backbone"),
605613
("hiera", "HieraBackbone"),
606614
("swin", "SwinBackbone"),
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2024 The HuggingFace Team. All rights reserved.
2+
#
3+
# This code is adapted from https://github.com/huggingface/transformers
4+
# with modifications to run transformers on mindspore.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
from .feature_extraction_convnext import *
18+
from .image_processing_convnext import *
19+
from .modeling_convnext import *
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# coding=utf-8
2+
# Copyright 2022 The HuggingFace Inc. team. All rights reserved.
3+
#
4+
# This code is adapted from https://github.com/huggingface/transformers
5+
# with modifications to run transformers on mindspore.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
"""Feature extractor class for ConvNeXT."""
19+
20+
import warnings
21+
22+
from ...utils import logging
23+
from .image_processing_convnext import ConvNextImageProcessor
24+
25+
logger = logging.get_logger(__name__)
26+
27+
28+
class ConvNextFeatureExtractor(ConvNextImageProcessor):
29+
def __init__(self, *args, **kwargs) -> None:
30+
warnings.warn(
31+
"The class ConvNextFeatureExtractor is deprecated and will be removed in version 5 of Transformers."
32+
" Please use ConvNextImageProcessor instead.",
33+
FutureWarning,
34+
)
35+
super().__init__(*args, **kwargs)
36+
37+
38+
__all__ = ["ConvNextFeatureExtractor"]

0 commit comments

Comments
 (0)