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
OpenDAS
dcnv3
Commits
ff20ea39
Unverified
Commit
ff20ea39
authored
Jan 06, 2025
by
Masahiro Ogawa
Committed by
GitHub
Jan 06, 2025
Browse files
Sort images and check the input image is assumed image format. (#246)
parent
3e3b4a5d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
8 deletions
+18
-8
segmentation/image_demo.py
segmentation/image_demo.py
+18
-8
No files found.
segmentation/image_demo.py
View file @
ff20ea39
...
@@ -15,15 +15,21 @@ import os
...
@@ -15,15 +15,21 @@ import os
def
test_single_image
(
model
,
img_name
,
out_dir
,
color_palette
,
opacity
):
def
test_single_image
(
model
,
img_name
,
out_dir
,
color_palette
,
opacity
):
# check img_name is an image file or not
assumed_imgformat
=
(
'.png'
,
'.jpg'
,
'.jpeg'
,
'.tiff'
,
'.bmp'
,
'.gif'
)
if
(
not
img_name
.
lower
().
endswith
(
assumed_imgformat
)):
print
(
f
"Skip
{
img_name
}
because it is not an image file."
)
return
result
=
inference_segmentor
(
model
,
img_name
)
result
=
inference_segmentor
(
model
,
img_name
)
# show the results
# show the results
if
hasattr
(
model
,
'module'
):
if
hasattr
(
model
,
'module'
):
model
=
model
.
module
model
=
model
.
module
img
=
model
.
show_result
(
img_name
,
result
,
img
=
model
.
show_result
(
img_name
,
result
,
palette
=
color_palette
,
palette
=
color_palette
,
show
=
False
,
opacity
=
opacity
)
show
=
False
,
opacity
=
opacity
)
# save the results
# save the results
mmcv
.
mkdir_or_exist
(
out_dir
)
mmcv
.
mkdir_or_exist
(
out_dir
)
out_path
=
osp
.
join
(
out_dir
,
osp
.
basename
(
img_name
))
out_path
=
osp
.
join
(
out_dir
,
osp
.
basename
(
img_name
))
...
@@ -33,7 +39,8 @@ def test_single_image(model, img_name, out_dir, color_palette, opacity):
...
@@ -33,7 +39,8 @@ def test_single_image(model, img_name, out_dir, color_palette, opacity):
def
main
():
def
main
():
parser
=
ArgumentParser
()
parser
=
ArgumentParser
()
parser
.
add_argument
(
'img'
,
help
=
'Image file or a directory contains images'
)
parser
.
add_argument
(
'img'
,
help
=
'Image file or a directory contains images'
)
parser
.
add_argument
(
'config'
,
help
=
'Config file'
)
parser
.
add_argument
(
'config'
,
help
=
'Config file'
)
parser
.
add_argument
(
'checkpoint'
,
help
=
'Checkpoint file'
)
parser
.
add_argument
(
'checkpoint'
,
help
=
'Checkpoint file'
)
parser
.
add_argument
(
'--out'
,
type
=
str
,
default
=
"demo"
,
help
=
'out dir'
)
parser
.
add_argument
(
'--out'
,
type
=
str
,
default
=
"demo"
,
help
=
'out dir'
)
...
@@ -58,13 +65,16 @@ def main():
...
@@ -58,13 +65,16 @@ def main():
model
.
CLASSES
=
checkpoint
[
'meta'
][
'CLASSES'
]
model
.
CLASSES
=
checkpoint
[
'meta'
][
'CLASSES'
]
else
:
else
:
model
.
CLASSES
=
get_classes
(
args
.
palette
)
model
.
CLASSES
=
get_classes
(
args
.
palette
)
# check arg.img is directory of a single image.
# check arg.img is directory of a single image.
if
osp
.
isdir
(
args
.
img
):
if
osp
.
isdir
(
args
.
img
):
for
img
in
os
.
listdir
(
args
.
img
):
for
img
in
sorted
(
os
.
listdir
(
args
.
img
)):
test_single_image
(
model
,
osp
.
join
(
args
.
img
,
img
),
args
.
out
,
get_palette
(
args
.
palette
),
args
.
opacity
)
test_single_image
(
model
,
osp
.
join
(
args
.
img
,
img
),
args
.
out
,
get_palette
(
args
.
palette
),
args
.
opacity
)
else
:
else
:
test_single_image
(
model
,
args
.
img
,
args
.
out
,
get_palette
(
args
.
palette
),
args
.
opacity
)
test_single_image
(
model
,
args
.
img
,
args
.
out
,
get_palette
(
args
.
palette
),
args
.
opacity
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
main
()
main
()
\ No newline at end of file
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