Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
5323094a
Unverified
Commit
5323094a
authored
Jun 09, 2022
by
regisss
Committed by
GitHub
Jun 09, 2022
Browse files
Add ONNX support for ResNet (#17585)
* Add ONNX support for ResNet * Add ONNX test * make fix-copies
parent
ca2a55e9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
2 deletions
+34
-2
docs/source/en/serialization.mdx
docs/source/en/serialization.mdx
+1
-0
src/transformers/models/resnet/__init__.py
src/transformers/models/resnet/__init__.py
+4
-2
src/transformers/models/resnet/configuration_resnet.py
src/transformers/models/resnet/configuration_resnet.py
+23
-0
src/transformers/onnx/features.py
src/transformers/onnx/features.py
+5
-0
tests/onnx/test_onnx_v2.py
tests/onnx/test_onnx_v2.py
+1
-0
No files found.
docs/source/en/serialization.mdx
View file @
5323094a
...
...
@@ -72,6 +72,7 @@ Ready-made configurations include the following architectures:
- OpenAI GPT-2
- Perceiver
- PLBart
- ResNet
- RoBERTa
- RoFormer
- SqueezeBERT
...
...
src/transformers/models/resnet/__init__.py
View file @
5323094a
...
...
@@ -21,7 +21,9 @@ from typing import TYPE_CHECKING
from
...utils
import
OptionalDependencyNotAvailable
,
_LazyModule
,
is_torch_available
_import_structure
=
{
"configuration_resnet"
:
[
"RESNET_PRETRAINED_CONFIG_ARCHIVE_MAP"
,
"ResNetConfig"
]}
_import_structure
=
{
"configuration_resnet"
:
[
"RESNET_PRETRAINED_CONFIG_ARCHIVE_MAP"
,
"ResNetConfig"
,
"ResNetOnnxConfig"
]
}
try
:
if
not
is_torch_available
():
...
...
@@ -38,7 +40,7 @@ else:
if
TYPE_CHECKING
:
from
.configuration_resnet
import
RESNET_PRETRAINED_CONFIG_ARCHIVE_MAP
,
ResNetConfig
from
.configuration_resnet
import
RESNET_PRETRAINED_CONFIG_ARCHIVE_MAP
,
ResNetConfig
,
ResNetOnnxConfig
try
:
if
not
is_torch_available
():
...
...
src/transformers/models/resnet/configuration_resnet.py
View file @
5323094a
...
...
@@ -14,7 +14,13 @@
# limitations under the License.
""" ResNet model configuration"""
from
collections
import
OrderedDict
from
typing
import
Mapping
from
packaging
import
version
from
...configuration_utils
import
PretrainedConfig
from
...onnx
import
OnnxConfig
from
...utils
import
logging
...
...
@@ -89,3 +95,20 @@ class ResNetConfig(PretrainedConfig):
self
.
layer_type
=
layer_type
self
.
hidden_act
=
hidden_act
self
.
downsample_in_first_stage
=
downsample_in_first_stage
class
ResNetOnnxConfig
(
OnnxConfig
):
torch_onnx_minimum_version
=
version
.
parse
(
"1.11"
)
@
property
def
inputs
(
self
)
->
Mapping
[
str
,
Mapping
[
int
,
str
]]:
return
OrderedDict
(
[
(
"pixel_values"
,
{
0
:
"batch"
,
1
:
"sequence"
}),
]
)
@
property
def
atol_for_validation
(
self
)
->
float
:
return
1e-3
src/transformers/onnx/features.py
View file @
5323094a
...
...
@@ -318,6 +318,11 @@ class FeaturesManager:
"sequence-classification"
,
onnx_config_cls
=
"models.perceiver.PerceiverOnnxConfig"
,
),
"resnet"
:
supported_features_mapping
(
"default"
,
"image-classification"
,
onnx_config_cls
=
"models.resnet.ResNetOnnxConfig"
,
),
"roberta"
:
supported_features_mapping
(
"default"
,
"masked-lm"
,
...
...
tests/onnx/test_onnx_v2.py
View file @
5323094a
...
...
@@ -182,6 +182,7 @@ PYTORCH_EXPORT_MODELS = {
(
"convbert"
,
"YituTech/conv-bert-base"
),
(
"distilbert"
,
"distilbert-base-cased"
),
(
"electra"
,
"google/electra-base-generator"
),
(
"resnet"
,
"microsoft/resnet-50"
),
(
"roberta"
,
"roberta-base"
),
(
"roformer"
,
"junnyu/roformer_chinese_base"
),
(
"squeezebert"
,
"squeezebert/squeezebert-uncased"
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment