Skip to content
Snippets Groups Projects
Unverified Commit 7ee9b8ec authored by Kai Chen's avatar Kai Chen Committed by GitHub
Browse files

add a demo to inference a single image (#2605)

parent f2f744a6
No related branches found
No related tags found
No related merge requests found
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()
......@@ -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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment