rename init/inference_segmentor to init/inference_model
parent
ad35ec6356
commit
c1c870af31
|
@ -9,7 +9,7 @@ from argparse import ArgumentParser
|
|||
import requests
|
||||
from mmcv import Config
|
||||
|
||||
from mmseg.apis import inference_segmentor, init_segmentor, show_result_pyplot
|
||||
from mmseg.apis import inference_model, init_model, show_result_pyplot
|
||||
from mmseg.utils import get_root_logger
|
||||
|
||||
# ignore warnings when segmentors inference
|
||||
|
@ -57,7 +57,7 @@ def parse_args():
|
|||
return args
|
||||
|
||||
|
||||
def inference_model(config_name, checkpoint, args, logger=None):
|
||||
def inference(config_name, checkpoint, args, logger=None):
|
||||
cfg = Config.fromfile(config_name)
|
||||
if args.aug:
|
||||
if 'flip' in cfg.data.test.pipeline[
|
||||
|
@ -72,9 +72,9 @@ def inference_model(config_name, checkpoint, args, logger=None):
|
|||
else:
|
||||
print(f'{config_name}: unable to start aug test', flush=True)
|
||||
|
||||
model = init_segmentor(cfg, checkpoint, device=args.device)
|
||||
model = init_model(cfg, checkpoint, device=args.device)
|
||||
# test a single image
|
||||
result = inference_segmentor(model, args.img)
|
||||
result = inference_model(model, args.img)
|
||||
|
||||
# show the results
|
||||
if args.show:
|
||||
|
@ -102,7 +102,7 @@ def main(args):
|
|||
model_info['checkpoint'].strip())
|
||||
try:
|
||||
# build the model from a config file and a checkpoint file
|
||||
inference_model(config_name, checkpoint, args)
|
||||
inference(config_name, checkpoint, args)
|
||||
except Exception:
|
||||
print(f'{config_name} test failed!')
|
||||
continue
|
||||
|
@ -139,7 +139,7 @@ def main(args):
|
|||
# test model inference with checkpoint
|
||||
try:
|
||||
# build the model from a config file and a checkpoint file
|
||||
inference_model(config_path, checkpoint, args, logger)
|
||||
inference(config_path, checkpoint, args, logger)
|
||||
except Exception as e:
|
||||
logger.error(f'{config_path} " : {repr(e)}')
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@
|
|||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from mmseg.apis import inference_segmentor, init_segmentor, show_result_pyplot\n",
|
||||
"from mmseg.apis import inference_model, init_model, show_result_pyplot\n",
|
||||
"from mmseg.core.evaluation import get_palette"
|
||||
]
|
||||
},
|
||||
|
@ -173,7 +173,7 @@
|
|||
"outputs": [],
|
||||
"source": [
|
||||
"# build the model from a config file and a checkpoint file\n",
|
||||
"model = init_segmentor(config_file, checkpoint_file, device='cuda:0')"
|
||||
"model = init_model(config_file, checkpoint_file, device='cuda:0')"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -186,7 +186,7 @@
|
|||
"source": [
|
||||
"# test a single image\n",
|
||||
"img = 'demo/demo.png'\n",
|
||||
"result = inference_segmentor(model, img)"
|
||||
"result = inference_model(model, img)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -596,7 +596,7 @@
|
|||
"img = mmcv.imread('iccv09Data/images/6000124.jpg')\n",
|
||||
"\n",
|
||||
"model.cfg = cfg\n",
|
||||
"result = inference_segmentor(model, img)\n",
|
||||
"result = inference_model(model, img)\n",
|
||||
"plt.figure(figsize=(8, 6))\n",
|
||||
"show_result_pyplot(model, img, result, palette)"
|
||||
]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
from argparse import ArgumentParser
|
||||
|
||||
from mmseg.apis import inference_segmentor, init_segmentor, show_result_pyplot
|
||||
from mmseg.apis import inference_model, init_model, show_result_pyplot
|
||||
from mmseg.core.evaluation import get_palette
|
||||
|
||||
|
||||
|
@ -24,9 +24,9 @@ def main():
|
|||
args = parser.parse_args()
|
||||
|
||||
# build the model from a config file and a checkpoint file
|
||||
model = init_segmentor(args.config, args.checkpoint, device=args.device)
|
||||
model = init_model(args.config, args.checkpoint, device=args.device)
|
||||
# test a single image
|
||||
result = inference_segmentor(model, args.img)
|
||||
result = inference_model(model, args.img)
|
||||
# show the results
|
||||
show_result_pyplot(
|
||||
model,
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from mmseg.apis import init_segmentor, inference_segmentor, show_result_pyplot\n",
|
||||
"from mmseg.apis import init_model, inference_model, show_result_pyplot\n",
|
||||
"from mmseg.core.evaluation import get_palette"
|
||||
]
|
||||
},
|
||||
|
@ -45,7 +45,7 @@
|
|||
"outputs": [],
|
||||
"source": [
|
||||
"# build the model from a config file and a checkpoint file\n",
|
||||
"model = init_segmentor(config_file, checkpoint_file, device='cuda:0')"
|
||||
"model = init_model(config_file, checkpoint_file, device='cuda:0')"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -56,7 +56,7 @@
|
|||
"source": [
|
||||
"# test a single image\n",
|
||||
"img = 'demo.png'\n",
|
||||
"result = inference_segmentor(model, img)"
|
||||
"result = inference_model(model, img)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@ from argparse import ArgumentParser
|
|||
|
||||
import cv2
|
||||
|
||||
from mmseg.apis import inference_segmentor, init_segmentor
|
||||
from mmseg.apis import inference_model, init_model
|
||||
from mmseg.core.evaluation import get_palette
|
||||
|
||||
|
||||
|
@ -52,7 +52,7 @@ def main():
|
|||
'At least one output should be enabled.'
|
||||
|
||||
# build the model from a config file and a checkpoint file
|
||||
model = init_segmentor(args.config, args.checkpoint, device=args.device)
|
||||
model = init_model(args.config, args.checkpoint, device=args.device)
|
||||
|
||||
# build input video
|
||||
cap = cv2.VideoCapture(args.video)
|
||||
|
@ -83,7 +83,7 @@ def main():
|
|||
break
|
||||
|
||||
# test a single image
|
||||
result = inference_segmentor(model, frame)
|
||||
result = inference_model(model, frame)
|
||||
|
||||
# blend raw image and prediction
|
||||
draw_img = model.show_result(
|
||||
|
|
|
@ -203,18 +203,18 @@ PYTHONPATH="$(dirname $0)/..":$PYTHONPATH
|
|||
To verify whether MMSegmentation and the required environment are installed correctly, we can run sample python codes to initialize a segmentor and inference a demo image:
|
||||
|
||||
```python
|
||||
from mmseg.apis import inference_segmentor, init_segmentor
|
||||
from mmseg.apis import inference_model, init_model
|
||||
import mmcv
|
||||
|
||||
config_file = 'configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py'
|
||||
checkpoint_file = 'checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth'
|
||||
|
||||
# build the model from a config file and a checkpoint file
|
||||
model = init_segmentor(config_file, checkpoint_file, device='cuda:0')
|
||||
model = init_model(config_file, checkpoint_file, device='cuda:0')
|
||||
|
||||
# test a single image and show the results
|
||||
img = 'test.jpg' # or img = mmcv.imread(img), which will only load it once
|
||||
result = inference_segmentor(model, img)
|
||||
result = inference_model(model, img)
|
||||
# visualize the results in a new window
|
||||
model.show_result(img, result, show=True)
|
||||
# or save the visualization results to image files
|
||||
|
@ -224,7 +224,7 @@ model.show_result(img, result, out_file='result.jpg', opacity=0.5)
|
|||
# test a video and show the results
|
||||
video = mmcv.VideoReader('video.mp4')
|
||||
for frame in video:
|
||||
result = inference_segmentor(model, frame)
|
||||
result = inference_model(model, frame)
|
||||
model.show_result(frame, result, wait_time=1)
|
||||
```
|
||||
|
||||
|
|
|
@ -203,18 +203,18 @@ PYTHONPATH="$(dirname $0)/..":$PYTHONPATH
|
|||
为了验证 MMSegmentation 和它所需要的环境是否正确安装,我们可以使用样例 python 代码来初始化一个 segmentor 并推理一张 demo 图像。
|
||||
|
||||
```python
|
||||
from mmseg.apis import inference_segmentor, init_segmentor
|
||||
from mmseg.apis import inference_model, init_model
|
||||
import mmcv
|
||||
|
||||
config_file = 'configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py'
|
||||
checkpoint_file = 'checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth'
|
||||
|
||||
# 从一个 config 配置文件和 checkpoint 文件里创建分割模型
|
||||
model = init_segmentor(config_file, checkpoint_file, device='cuda:0')
|
||||
model = init_model(config_file, checkpoint_file, device='cuda:0')
|
||||
|
||||
# 测试一张样例图片并得到结果
|
||||
img = 'test.jpg' # 或者 img = mmcv.imread(img), 这将只加载图像一次.
|
||||
result = inference_segmentor(model, img)
|
||||
result = inference_model(model, img)
|
||||
# 在新的窗口里可视化结果
|
||||
model.show_result(img, result, show=True)
|
||||
# 或者保存图片文件的可视化结果
|
||||
|
@ -224,7 +224,7 @@ model.show_result(img, result, out_file='result.jpg', opacity=0.5)
|
|||
# 测试一个视频并得到分割结果
|
||||
video = mmcv.VideoReader('video.mp4')
|
||||
for frame in video:
|
||||
result = inference_segmentor(model, frame)
|
||||
result = inference_model(model, frame)
|
||||
model.show_result(frame, result, wait_time=1)
|
||||
```
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
from .inference import inference_segmentor, init_segmentor, show_result_pyplot
|
||||
from .inference import inference_model, init_model, show_result_pyplot
|
||||
|
||||
__all__ = ['init_segmentor', 'inference_segmentor', 'show_result_pyplot']
|
||||
__all__ = ['init_model', 'inference_model', 'show_result_pyplot']
|
||||
|
|
|
@ -9,7 +9,7 @@ from mmseg.datasets.pipelines import Compose
|
|||
from mmseg.models import build_segmentor
|
||||
|
||||
|
||||
def init_segmentor(config, checkpoint=None, device='cuda:0'):
|
||||
def init_model(config, checkpoint=None, device='cuda:0'):
|
||||
"""Initialize a segmentor from config file.
|
||||
|
||||
Args:
|
||||
|
@ -67,7 +67,7 @@ class LoadImage:
|
|||
return results
|
||||
|
||||
|
||||
def inference_segmentor(model, img):
|
||||
def inference_model(model, img):
|
||||
"""Inference image(s) with the segmentor.
|
||||
|
||||
Args:
|
||||
|
|
|
@ -4,7 +4,7 @@ import warnings
|
|||
|
||||
from mmcv import Config, DictAction
|
||||
|
||||
from mmseg.apis import init_segmentor
|
||||
from mmseg.apis import init_model
|
||||
|
||||
|
||||
def parse_args():
|
||||
|
@ -59,7 +59,7 @@ def main():
|
|||
cfg.dump('example.py')
|
||||
# dump models graph
|
||||
if args.graph:
|
||||
model = init_segmentor(args.config, device='cpu')
|
||||
model = init_model(args.config, device='cpu')
|
||||
print(f'Model graph:\n{str(model)}')
|
||||
with open('example-graph.txt', 'w') as f:
|
||||
f.writelines(str(model))
|
||||
|
|
|
@ -8,7 +8,7 @@ import torch
|
|||
from mmcv.cnn.utils.sync_bn import revert_sync_batchnorm
|
||||
from ts.torch_handler.base_handler import BaseHandler
|
||||
|
||||
from mmseg.apis import inference_segmentor, init_segmentor
|
||||
from mmseg.apis import inference_model, init_model
|
||||
|
||||
|
||||
class MMsegHandler(BaseHandler):
|
||||
|
@ -26,7 +26,7 @@ class MMsegHandler(BaseHandler):
|
|||
checkpoint = os.path.join(model_dir, serialized_file)
|
||||
self.config_file = os.path.join(model_dir, 'config.py')
|
||||
|
||||
self.model = init_segmentor(self.config_file, checkpoint, self.device)
|
||||
self.model = init_model(self.config_file, checkpoint, self.device)
|
||||
self.model = revert_sync_batchnorm(self.model)
|
||||
self.initialized = True
|
||||
|
||||
|
@ -43,7 +43,7 @@ class MMsegHandler(BaseHandler):
|
|||
return images
|
||||
|
||||
def inference(self, data, *args, **kwargs):
|
||||
results = [inference_segmentor(self.model, img) for img in data]
|
||||
results = [inference_model(self.model, img) for img in data]
|
||||
return results
|
||||
|
||||
def postprocess(self, data):
|
||||
|
|
|
@ -6,7 +6,7 @@ import matplotlib.pyplot as plt
|
|||
import mmcv
|
||||
import requests
|
||||
|
||||
from mmseg.apis import inference_segmentor, init_segmentor
|
||||
from mmseg.apis import inference_model, init_model
|
||||
|
||||
|
||||
def parse_args():
|
||||
|
@ -46,9 +46,9 @@ def main(args):
|
|||
else:
|
||||
plt.imshow(plt.imread(BytesIO(content)))
|
||||
plt.show()
|
||||
model = init_segmentor(args.config, args.checkpoint, args.device)
|
||||
model = init_model(args.config, args.checkpoint, args.device)
|
||||
image = mmcv.imread(args.img)
|
||||
result = inference_segmentor(model, image)
|
||||
result = inference_model(model, image)
|
||||
plt.imshow(result[0])
|
||||
plt.show()
|
||||
|
||||
|
|
Loading…
Reference in New Issue