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
1ddf3c2b
"git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "30677dc743bae5485f755392adf4d543f71db6e4"
Unverified
Commit
1ddf3c2b
authored
Feb 15, 2022
by
Lysandre Debut
Committed by
GitHub
Feb 15, 2022
Browse files
Fix vit test (#15671)
parent
943e2aa0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
33 deletions
+11
-33
tests/test_pipelines_image_classification.py
tests/test_pipelines_image_classification.py
+11
-33
No files found.
tests/test_pipelines_image_classification.py
View file @
1ddf3c2b
...
...
@@ -113,19 +113,13 @@ class ImageClassificationPipelineTests(unittest.TestCase, metaclass=PipelineTest
@
require_torch
def
test_small_model_pt
(
self
):
small_model
=
"
lysandre
/tiny-
vit-
random"
small_model
=
"
hf-internal-testing
/tiny-random
-vit
"
image_classifier
=
pipeline
(
"image-classification"
,
model
=
small_model
)
outputs
=
image_classifier
(
"http://images.cocodataset.org/val2017/000000039769.jpg"
)
self
.
assertEqual
(
nested_simplify
(
outputs
,
decimals
=
4
),
[
{
"score"
:
0.0015
,
"label"
:
"chambered nautilus, pearly nautilus, nautilus"
},
{
"score"
:
0.0015
,
"label"
:
"pajama, pyjama, pj's, jammies"
},
{
"score"
:
0.0014
,
"label"
:
"trench coat"
},
{
"score"
:
0.0014
,
"label"
:
"handkerchief, hankie, hanky, hankey"
},
{
"score"
:
0.0014
,
"label"
:
"baboon"
},
],
[{
"label"
:
"LABEL_1"
,
"score"
:
0.574
},
{
"label"
:
"LABEL_0"
,
"score"
:
0.426
}],
)
outputs
=
image_classifier
(
...
...
@@ -138,32 +132,20 @@ class ImageClassificationPipelineTests(unittest.TestCase, metaclass=PipelineTest
self
.
assertEqual
(
nested_simplify
(
outputs
,
decimals
=
4
),
[
[
{
"score"
:
0.0015
,
"label"
:
"chambered nautilus, pearly nautilus, nautilus"
},
{
"score"
:
0.0015
,
"label"
:
"pajama, pyjama, pj's, jammies"
},
],
[
{
"score"
:
0.0015
,
"label"
:
"chambered nautilus, pearly nautilus, nautilus"
},
{
"score"
:
0.0015
,
"label"
:
"pajama, pyjama, pj's, jammies"
},
],
[{
"label"
:
"LABEL_1"
,
"score"
:
0.574
},
{
"label"
:
"LABEL_0"
,
"score"
:
0.426
}],
[{
"label"
:
"LABEL_1"
,
"score"
:
0.574
},
{
"label"
:
"LABEL_0"
,
"score"
:
0.426
}],
],
)
@
require_tf
def
test_small_model_tf
(
self
):
small_model
=
"
lysandre
/tiny-
vit-
random"
small_model
=
"
hf-internal-testing
/tiny-random
-vit
"
image_classifier
=
pipeline
(
"image-classification"
,
model
=
small_model
)
outputs
=
image_classifier
(
"http://images.cocodataset.org/val2017/000000039769.jpg"
)
self
.
assertEqual
(
nested_simplify
(
outputs
,
decimals
=
4
),
[
{
"score"
:
0.0015
,
"label"
:
"chambered nautilus, pearly nautilus, nautilus"
},
{
"score"
:
0.0015
,
"label"
:
"pajama, pyjama, pj's, jammies"
},
{
"score"
:
0.0014
,
"label"
:
"trench coat"
},
{
"score"
:
0.0014
,
"label"
:
"handkerchief, hankie, hanky, hankey"
},
{
"score"
:
0.0014
,
"label"
:
"baboon"
},
],
[{
"label"
:
"LABEL_1"
,
"score"
:
0.574
},
{
"label"
:
"LABEL_0"
,
"score"
:
0.426
}],
)
outputs
=
image_classifier
(
...
...
@@ -176,14 +158,8 @@ class ImageClassificationPipelineTests(unittest.TestCase, metaclass=PipelineTest
self
.
assertEqual
(
nested_simplify
(
outputs
,
decimals
=
4
),
[
[
{
"score"
:
0.0015
,
"label"
:
"chambered nautilus, pearly nautilus, nautilus"
},
{
"score"
:
0.0015
,
"label"
:
"pajama, pyjama, pj's, jammies"
},
],
[
{
"score"
:
0.0015
,
"label"
:
"chambered nautilus, pearly nautilus, nautilus"
},
{
"score"
:
0.0015
,
"label"
:
"pajama, pyjama, pj's, jammies"
},
],
[{
"label"
:
"LABEL_1"
,
"score"
:
0.574
},
{
"label"
:
"LABEL_0"
,
"score"
:
0.426
}],
[{
"label"
:
"LABEL_1"
,
"score"
:
0.574
},
{
"label"
:
"LABEL_0"
,
"score"
:
0.426
}],
],
)
...
...
@@ -191,7 +167,9 @@ class ImageClassificationPipelineTests(unittest.TestCase, metaclass=PipelineTest
tokenizer
=
PreTrainedTokenizer
()
# Assert that the pipeline can be initialized with a feature extractor that is not in any mapping
image_classifier
=
pipeline
(
"image-classification"
,
model
=
"lysandre/tiny-vit-random"
,
tokenizer
=
tokenizer
)
image_classifier
=
pipeline
(
"image-classification"
,
model
=
"hf-internal-testing/tiny-random-vit"
,
tokenizer
=
tokenizer
)
self
.
assertIs
(
image_classifier
.
tokenizer
,
tokenizer
)
...
...
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