open-mmlab / mmsegmentation

OpenMMLab Semantic Segmentation Toolbox and Benchmark.
https://mmsegmentation.readthedocs.io/en/main/
Apache License 2.0
8.03k stars 2.58k forks source link

rs_image_inference #3772

Open dongxiaofei12 opened 1 week ago

dongxiaofei12 commented 1 week ago

Why the result is black when I use this.

dongxiaofei12 commented 1 week ago

And if I want to superimpose my inference onto the original, how do I do that?

JohnalDsouza commented 1 day ago

i dont understand your question, but if u want to impose the inference on the original image you can use opacity

config_file = 'pspnet_r50-d8_4xb2-40k_cityscapes-512x1024.py' checkpoint_file = 'pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth'

config_file = 'segformer_mit-b2_8x1_1024x1024_160k_kitti.py'

checkpoint_file = 'checkpoints/Segformer_B2.pth'

Initialize the model

model = init_model(config_file, checkpoint_file, device='cuda:0')

Load an image

img = 'demo/image.png' # or img = mmcv.imread(img)

Run inference

result = inference_model(model, img)

Save and display the result

output_file = 'result.jpg' show_result_pyplot(model, img, result, show=False, out_file=output_file, opacity=0.5)

image = cv2.imread(output_file) image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # Convert BGR to RGB for correct display

plt.figure(figsize=(10, 10)) plt.imshow(image) plt.axis('off') # Turn off axis plt.show()