mmsegmentation对比不同模型推理效果

from mmseg.apis import inference_segmentor, init_segmentor
import mmcv
import cv2
import time
from matplotlib import pyplot as plt
import numpy as np


def deployNet(resized_img,config_file, checkpoint_file):
    # 通过配置文件和模型权重文件构建模型
    model = init_segmentor(config_file, checkpoint_file, device='cuda:0')
    # 对单张图片进行推理并展示结果
    # img = 'test.jpg'  # or img = mmcv.imread(img), which will only load it once
    time_start = time.time()
    result = inference_segmentor(model, resized_img)
    time_end = time.time()
    print(f"time_end={time_end - time_start}")
    # 你可以修改 opacity 在(0,1]之间的取值来改变绘制好的分割图的透明度
    img = model.show_result(resized_img, result, opacity=1)
    return img, time_end - time_start

def coverLabelToGroup6(seg):
    seg=np.max(seg,axis=2)
    palette = [[0, 0, 0], [0, 128, 0], [255, 255, 0], [255, 128, 0], [255, 0, 0], [0, 0, 128]]
    color_seg = np.zeros((seg.shape[0], seg.shape[1], 3), dtype=np.uint8)
    for label, color in enumerate(palette):
        color_seg[seg == label, :] = color
    return color_seg

img = mmcv.imread(r'C:\Users\63108\Desktop\GANav-offroad-main\tools\creek_00156.png')
dim = (688, 550)
resized_img = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
label = cv2.imread(r'C:\Users\63108\Desktop\GANav-offroad-main\data\rugd\RUGD_annotations\creek\creek_00156_group6.png')
label=coverLabelToGroup6(label)


# ganav_rugd_6 yure
config_file = r'C:\Users\63108\Desktop\GANav-offroad-main\trained_models\rugd_group6\ganav_rugd_6.py'
checkpoint_file = r'C:\Users\63108\Desktop\GANav-offroad-main\trained_models\rugd_group6\ganav_rugd_6.pth'
img1, time1 = deployNet(resized_img,config_file, checkpoint_file)
img1 = img1[..., ::-1]


# mogai_rugd6
config_file = r'C:\Users\63108\Desktop\GANav-offroad-main\work_dirs\mogai_rugd_6\mogai_rugd6.py'
checkpoint_file = r'C:\Users\63108\Desktop\GANav-offroad-main\work_dirs\mogai_rugd_6\best_mIoU_iter_104000.pth'
img2, time2 = deployNet(resized_img,config_file, checkpoint_file)
img2 = img2[..., ::-1]
# lpsnet
config_file = r'C:\Users\63108\Desktop\GANav-offroad-main\configs\lps-net\lpsnet.py'
checkpoint_file = r'C:\Users\63108\Desktop\GANav-offroad-main\work_dirs\lspnet_rugd6\best_mIoU_iter_28800.pth'
img3, time3 = deployNet(resized_img,config_file, checkpoint_file)
img3 = img3[..., ::-1]

# 画对比图
plt.subplots_adjust(bottom=0, left=.01, right=.99, top=.90, hspace=.35)
plt.subplot(1,4,1)
plt.imshow(label)
plt.xticks(())
plt.yticks(())
plt.title("label")
plt.subplot(1,4,2)
plt.imshow(img1)
plt.xticks(())
plt.yticks(())
plt.title("ganav_rugd_6 \n time ={}".format(round(time1,4)))
plt.subplot(1,4,3)
plt.imshow(img2)
plt.xticks(())
plt.yticks(())
plt.title("mogai_rugd6\n time ={}".format(round(time2,4)))
plt.subplot(1,4,4)
plt.xticks(())
plt.yticks(())
plt.title("lpsnet \n time ={}".format(round(time3,4)))
plt.imshow(img3)
plt.show()

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值