Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Fix image_demo.py error #1640

Merged
merged 4 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion demo/image_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def main():
parser.add_argument('img', help='Image file')
parser.add_argument('config', help='Config file')
parser.add_argument('checkpoint', help='Checkpoint file')
parser.add_argument('--out-file', default=None, help='Path to output file')
parser.add_argument(
'--device', default='cuda:0', help='Device used for inference')
parser.add_argument(
Expand All @@ -33,7 +34,8 @@ def main():
args.img,
result,
get_palette(args.palette),
opacity=args.opacity)
opacity=args.opacity,
out_file=args.out_file)


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion docs/en/get_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ The downloading will take several seconds or more, depending on your network env
Option (a). If you install mmsegmentation from source, just run the following command.

```shell
python demo/image_demo.py demo/demo.jpg pspnet_r50-d8_512x1024_40k_cityscapes.py pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth --device cpu --out-file result.jpg
python demo/image_demo.py demo/demo.png configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth --device cuda:0 --out-file result.jpg
```

You will see a new image `result.jpg` on your current folder, where segmentation masks are covered on all objects.
Expand Down
7 changes: 6 additions & 1 deletion mmseg/apis/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def show_result_pyplot(model,
fig_size=(15, 10),
opacity=0.5,
title='',
block=True):
block=True,
out_file=None):
"""Visualize the segmentation results on the image.

Args:
Expand All @@ -124,6 +125,8 @@ def show_result_pyplot(model,
Default is ''.
block (bool): Whether to block the pyplot figure.
Default is True.
out_file (str or None): The path to write the image.
Default: None.
"""
if hasattr(model, 'module'):
model = model.module
Expand All @@ -134,3 +137,5 @@ def show_result_pyplot(model,
plt.title(title)
plt.tight_layout()
plt.show(block=block)
if out_file is not None:
mmcv.imwrite(img, out_file)