mirror of
https://github.com/open-mmlab/mmsegmentation.git
synced 2025-06-03 22:03:48 +08:00
## Motivation Supports inference for ultra-large-scale remote sensing images. ## Modification Add RSImageInference.py in demo. ## Use cases Taking the inference of Vaihingen dataset images using PSPNet as an example, the following settings are required: **img**: Specify the path of the image. **model**: Provide the configuration file for the model. **checkpoint**: Specify the weight file for the model. **out**: Set the output path for the results. **batch_size**: Determine the batch size used during inference. **win_size**: Specify the width and height(512x512) of the sliding window. **stride**: Set the stride(400x400) for sliding the window. **thread(default: 1)**: Specify the number of threads to be used for inference. **Inference device (default: cuda:0)**: Specify the device for inference (e.g., cuda:0 for CPU). ```shell python demo/rs_image_inference.py demo/demo.png projects/pp_mobileseg/configs/pp_mobileseg/pp_mobileseg_mobilenetv3_2x16_80k_ade20k_512x512_tiny.py pp_mobileseg_mobilenetv3_2xb16_3rdparty-tiny_512x512-ade20k-a351ebf5.pth --batch-size 8 --device cpu --thread 2 ``` --------- Co-authored-by: xiexinch <xiexinch@outlook.com>
51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
# Copyright (c) OpenMMLab. All rights reserved.
|
|
from argparse import ArgumentParser
|
|
|
|
from mmseg.apis import RSImage, RSInferencer
|
|
|
|
|
|
def main():
|
|
parser = ArgumentParser()
|
|
parser.add_argument('image', help='Image file path')
|
|
parser.add_argument('config', help='Config file')
|
|
parser.add_argument('checkpoint', help='Checkpoint file')
|
|
parser.add_argument(
|
|
'--output-path',
|
|
help='Path to save result image',
|
|
default='result.png')
|
|
parser.add_argument(
|
|
'--batch-size',
|
|
type=int,
|
|
default=1,
|
|
help='maximum number of windows inferred simultaneously')
|
|
parser.add_argument(
|
|
'--window-size',
|
|
help='window xsize,ysize',
|
|
default=(224, 224),
|
|
type=int,
|
|
nargs=2)
|
|
parser.add_argument(
|
|
'--stride',
|
|
help='window xstride,ystride',
|
|
default=(224, 224),
|
|
type=int,
|
|
nargs=2)
|
|
parser.add_argument(
|
|
'--thread', default=1, type=int, help='number of inference threads')
|
|
parser.add_argument(
|
|
'--device', default='cuda:0', help='Device used for inference')
|
|
args = parser.parse_args()
|
|
inferencer = RSInferencer.from_config_path(
|
|
args.config,
|
|
args.checkpoint,
|
|
batch_size=args.batch_size,
|
|
thread=args.thread,
|
|
device=args.device)
|
|
image = RSImage(args.image)
|
|
|
|
inferencer.run(image, args.window_size, args.stride, args.output_path)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|