Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Swin-Transformer-Object-Detection
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wanggh
Swin-Transformer-Object-Detection
Commits
7ee9b8ec
Unverified
Commit
7ee9b8ec
authored
4 years ago
by
Kai Chen
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
add a demo to inference a single image (#2605)
parent
f2f744a6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
demo/image_demo.py
+24
-0
24 additions, 0 deletions
demo/image_demo.py
mmdet/apis/inference.py
+2
-7
2 additions, 7 deletions
mmdet/apis/inference.py
with
26 additions
and
7 deletions
demo/image_demo.py
0 → 100644
+
24
−
0
View file @
7ee9b8ec
from
argparse
import
ArgumentParser
from
mmdet.apis
import
inference_detector
,
init_detector
,
show_result_pyplot
def
main
():
parser
=
ArgumentParser
()
parser
.
add_argument
(
'
img
'
,
help
=
'
Image file
'
)
parser
.
add_argument
(
'
config
'
,
help
=
'
Config file
'
)
parser
.
add_argument
(
'
checkpoint
'
,
help
=
'
Checkpoint file
'
)
parser
.
add_argument
(
'
--device
'
,
default
=
'
cuda:0
'
,
help
=
'
Device used for inference
'
)
args
=
parser
.
parse_args
()
# build the model from a config file and a checkpoint file
model
=
init_detector
(
args
.
config
,
args
.
checkpoint
,
device
=
args
.
device
)
# test a single image
result
=
inference_detector
(
model
,
args
.
img
)
# show the results
show_result_pyplot
(
model
,
args
.
img
,
result
)
if
__name__
==
'
__main__
'
:
main
()
This diff is collapsed.
Click to expand it.
mmdet/apis/inference.py
+
2
−
7
View file @
7ee9b8ec
...
...
@@ -130,12 +130,7 @@ async def async_inference_detector(model, img):
return
result
def
show_result_pyplot
(
model
,
img
,
result
,
class_names
,
score_thr
=
0.3
,
fig_size
=
(
15
,
10
)):
def
show_result_pyplot
(
model
,
img
,
result
,
score_thr
=
0.3
,
fig_size
=
(
15
,
10
)):
"""
Visualize the detection results on the image.
Args:
...
...
@@ -143,7 +138,6 @@ def show_result_pyplot(model,
img (str or np.ndarray): Image filename or loaded image.
result (tuple[list] or list): The detection result, can be either
(bbox, segm) or just bbox.
class_names (list[str] or tuple[str]): A list of class names.
score_thr (float): The threshold to visualize the bboxes and masks.
fig_size (tuple): Figure size of the pyplot figure.
"""
...
...
@@ -152,3 +146,4 @@ def show_result_pyplot(model,
img
=
model
.
show_result
(
img
,
result
,
score_thr
=
score_thr
,
show
=
False
)
plt
.
figure
(
figsize
=
fig_size
)
plt
.
imshow
(
mmcv
.
bgr2rgb
(
img
))
plt
.
show
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment