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

[Feature] Support MMSegInferencer #2413

Merged
merged 15 commits into from
Feb 23, 2023

Conversation

xiexinch
Copy link
Collaborator

@xiexinch xiexinch commented Dec 15, 2022

Motivation

Support MMSegInferencer for providing an easy and clean interface for single or multiple images inferencing.

Ref: open-mmlab/mmengine#773 open-mmlab/mmocr#1608

Modification

  • mmseg/apis/mmseg_inferencer.py
  • mmseg/visualization/local_visualizer.py
  • demo/image_demo_with_inferencer.py

Use cases (Optional)

Based on https://github.com/open-mmlab/mmengine/tree/inference

Add a new image inference demo with MMSegInferencer

  • demo/image_demo_with_inferencer.py
python demo/image_demo_with_inferencer.py demo/demo.png fcn_r50-d8_4xb2-40k_cityscapes-512x1024

@xiexinch xiexinch added WIP Work in process 1.x Related issue of 1.x version labels Dec 15, 2022
@codecov
Copy link

codecov bot commented Dec 15, 2022

Codecov Report

Base: 83.29% // Head: 83.52% // Increases project coverage by +0.23% 🎉

Coverage data is based on head (5686162) compared to base (039ba5d).
Patch coverage: 73.14% of modified lines in pull request are covered.

❗ Current head 5686162 differs from pull request most recent head 39076e8. Consider uploading reports for the commit 39076e8 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           dev-1.x    #2413      +/-   ##
===========================================
+ Coverage    83.29%   83.52%   +0.23%     
===========================================
  Files          146      147       +1     
  Lines         8522     8620      +98     
  Branches      1275     1293      +18     
===========================================
+ Hits          7098     7200     +102     
+ Misses        1212     1195      -17     
- Partials       212      225      +13     
Flag Coverage Δ
unittests 83.52% <73.14%> (+0.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mmseg/datasets/transforms/loading.py 81.37% <55.55%> (-3.78%) ⬇️
mmseg/apis/mmseg_inferencer.py 74.35% <74.35%> (ø)
mmseg/visualization/local_visualizer.py 98.27% <88.88%> (+0.06%) ⬆️
mmseg/__init__.py 92.10% <100.00%> (ø)
mmseg/apis/__init__.py 100.00% <100.00%> (+100.00%) ⬆️
mmseg/datasets/transforms/transforms.py 90.40% <0.00%> (+0.90%) ⬆️
mmseg/models/data_preprocessor.py 95.55% <0.00%> (+2.22%) ⬆️
mmseg/apis/inference.py 23.15% <0.00%> (+23.15%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@xiexinch xiexinch removed the WIP Work in process label Jan 29, 2023
wait_time: int = 0,
draw_pred: bool = True,
out_dir: str = '',
print_result: bool = False,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print_result might be not suit for segmentation task?

Comment on lines 91 to 110
def visualize(self,
inputs: list,
preds: List[dict],
return_vis: bool = False,
show: bool = False,
wait_time: int = 0,
draw_pred: bool = True,
img_out_dir: str = '',
opacity: float = 0.8) -> List[np.ndarray]:
"""Visualize predictions.

Args:
inputs (list): Inputs preprocessed by :meth:`_inputs_to_list`.
preds (Any): Predictions of the model.
show (bool): Whether to display the image in a popup window.
Defaults to False.

Returns:
List[np.ndarray]: Visualization results.
"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add docstring for this kwargs

def visualize(self,
inputs: list,
preds: List[dict],
return_vis: bool = False,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think return_vis might not work?

Copy link
Collaborator

@MeowZheng MeowZheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please modify mmcv version in requirement/mminstall.txt

infer = MMSegInferencer(cfg, ckpt_filename)

# test forward
img = np.random.randint(0, 256, (4, 4, 3)).astype(np.float32)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the input data type is np.float32?

Comment on lines 21 to 22
"""MMSegInferencer.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might add MMSegInferencer needs mmengine>=0.5.0 in docstring

@MeowZheng MeowZheng merged commit 53fe1cc into open-mmlab:dev-1.x Feb 23, 2023
nahidnazifi87 pushed a commit to nahidnazifi87/mmsegmentation_playground that referenced this pull request Apr 5, 2024
## Motivation

Support `MMSegInferencer` for providing an easy and clean interface for
single or multiple images inferencing.

Ref: open-mmlab/mmengine#773
open-mmlab/mmocr#1608

## Modification

- mmseg/apis/mmseg_inferencer.py
- mmseg/visualization/local_visualizer.py
- demo/image_demo_with_inferencer.py

## Use cases (Optional)

Based on https://github.com/open-mmlab/mmengine/tree/inference

Add a new image inference demo with `MMSegInferencer`

- demo/image_demo_with_inferencer.py

```shell
python demo/image_demo_with_inferencer.py demo/demo.png fcn_r50-d8_4xb2-40k_cityscapes-512x1024
```

---------

Co-authored-by: MeowZheng <meowzheng@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x Related issue of 1.x version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants