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
e6122c3f
Unverified
Commit
e6122c3f
authored
Jun 15, 2023
by
amyeroberts
Committed by
GitHub
Jun 15, 2023
Browse files
Fix image segmentation tool bug (#23897)
* Image segmentation tool bug * Remove resizing in the tests
parent
6cd34d45
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
5 deletions
+4
-5
src/transformers/tools/image_segmentation.py
src/transformers/tools/image_segmentation.py
+0
-1
tests/tools/test_image_segmentation.py
tests/tools/test_image_segmentation.py
+4
-4
No files found.
src/transformers/tools/image_segmentation.py
View file @
e6122c3f
...
...
@@ -44,7 +44,6 @@ class ImageSegmentationTool(PipelineTool):
super
().
__init__
(
*
args
,
**
kwargs
)
def
encode
(
self
,
image
:
"Image"
,
label
:
str
):
self
.
pre_processor
.
image_processor
.
size
=
{
"width"
:
image
.
size
[
0
],
"height"
:
image
.
size
[
1
]}
return
self
.
pre_processor
(
text
=
[
label
],
images
=
[
image
],
padding
=
True
,
return_tensors
=
"pt"
)
def
forward
(
self
,
inputs
):
...
...
tests/tools/test_image_segmentation.py
View file @
e6122c3f
...
...
@@ -33,21 +33,21 @@ class ImageSegmentationToolTester(unittest.TestCase, ToolTesterMixin):
self
.
remote_tool
=
load_tool
(
"image-segmentation"
,
remote
=
True
)
def
test_exact_match_arg
(
self
):
image
=
Image
.
open
(
Path
(
get_tests_dir
(
"fixtures/tests_samples/COCO"
))
/
"000000039769.png"
)
.
resize
((
512
,
512
))
image
=
Image
.
open
(
Path
(
get_tests_dir
(
"fixtures/tests_samples/COCO"
))
/
"000000039769.png"
)
result
=
self
.
tool
(
image
,
"cat"
)
self
.
assertTrue
(
isinstance
(
result
,
Image
.
Image
))
def
test_exact_match_arg_remote
(
self
):
image
=
Image
.
open
(
Path
(
get_tests_dir
(
"fixtures/tests_samples/COCO"
))
/
"000000039769.png"
)
.
resize
((
512
,
512
))
image
=
Image
.
open
(
Path
(
get_tests_dir
(
"fixtures/tests_samples/COCO"
))
/
"000000039769.png"
)
result
=
self
.
remote_tool
(
image
,
"cat"
)
self
.
assertTrue
(
isinstance
(
result
,
Image
.
Image
))
def
test_exact_match_kwarg
(
self
):
image
=
Image
.
open
(
Path
(
get_tests_dir
(
"fixtures/tests_samples/COCO"
))
/
"000000039769.png"
)
.
resize
((
512
,
512
))
image
=
Image
.
open
(
Path
(
get_tests_dir
(
"fixtures/tests_samples/COCO"
))
/
"000000039769.png"
)
result
=
self
.
tool
(
image
=
image
,
label
=
"cat"
)
self
.
assertTrue
(
isinstance
(
result
,
Image
.
Image
))
def
test_exact_match_kwarg_remote
(
self
):
image
=
Image
.
open
(
Path
(
get_tests_dir
(
"fixtures/tests_samples/COCO"
))
/
"000000039769.png"
)
.
resize
((
512
,
512
))
image
=
Image
.
open
(
Path
(
get_tests_dir
(
"fixtures/tests_samples/COCO"
))
/
"000000039769.png"
)
result
=
self
.
remote_tool
(
image
=
image
,
label
=
"cat"
)
self
.
assertTrue
(
isinstance
(
result
,
Image
.
Image
))
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