mmgmentation日常学习与源码解读

更新时间:2023-07-18 08:00:34 阅读: 评论:0

mmgmentation⽇常学习与源码解读1. mmgmentation保存预测的结果,不覆盖原图
⾸先找到源码中对应的⽂件 ba.py
对应的代码⽚段如下:
def show_result(lf,
img,
result,
palette=None,
win_name='',
show=Fal,
wait_time=0,
out_file=None,
opacity=0.5):
"""Draw `result` over `img`.
Args:
img (str or Tensor): The image to be displayed.
result (Tensor): The mantic gmentation results to draw over
`img`.
palette (list[list[int]]] | np.ndarray | None): The palette of
gmentation map. If None is given, random palette will be
generated. Default: None
win_name (str): The window name.
wait_time (int): Value of waitKey param.
Default: 0.
show (bool): Whether to show the image.
Default: Fal.
有趣故事
out_file (str or None): The filename to write the image.
Default: None.
歌颂祖国作文opacity(float): Opacity of painted gmentation map.
Default 0.5.
Must be in (0, 1] range.
Returns:
img (Tensor): Only if not `show` or `out_file`
"""
化痰止咳药img = mmcv.imread(img)
img = py()
g = result[0]
企业合同管理if palette is None:
if lf.PALETTE is None:
# Get random state before t ed,
# and restore random state later.
# It will prevent loss of randomness, as the palette
# may be different in each iteration if not specified.
# may be different in each iteration if not specified.
# See: /open-mmlab/mmdetection/issues/5844
state = _state()
np.random.ed(42)
画月亮# random palette
palette = np.random.randint(
0,255, size=(len(lf.CLASSES),3))宫颈纳氏囊肿怎么处理
np.random.t_state(state)
el:
palette = lf.PALETTE
palette = np.array(palette)
asrt palette.shape[0]==len(lf.CLASSES)
asrt palette.shape[1]==3
asrt len(palette.shape)==2
asrt0< opacity <=1.0
color_g = np.zeros((g.shape[0], g.shape[1],3), dtype=np.uint8)
伤感句
for label, color in enumerate(palette):
color_g[g == label,:]= color
# convert to BGR
color_g = color_g[...,::-1]
中国都江堰img = img *(1- opacity)+ color_g * opacity
img = img.astype(np.uint8)
# if out_file specified, do not show image in window
if out_file is not None:
show =Fal
if show:
mmcv.imshow(img, win_name, wait_time)
if out_file is not None:
mmcv.imwrite(img, out_file)
# 关于mmgmentation保存预测结果 /p/380178024
# mmgmentation默认将预测得到的mask覆盖在原始图⽚上进⾏显⽰或保存,为了直接输出灰度图,需要对源码进⾏修改
# 以⼆分类为例,可修改为
# if out_file is not None:
#    g = np.array(g)
#    g[g > 0] = 255
#    mmcv.imwrite(g, out_file)
# 对于⼆分类可如⽂末形式进⾏修改;对于多分类,可在⽂中标记修改处修改为mmcv.imwrite(color_g, out_file),此时将保存通过调⾊板转换后的彩⾊图,若想保存灰度图,则在
修改处修改为mmcv.imwrite(g, out_file)即可
if not(show or out_file):
warnings.warn('show==Fal and out_file is not specified, only '
'result image will be returned')
return img
2. python的函数装饰器
看了很多次 今天终于懂⼀点点了,记住了⼀些帮助理解的关键句

本文发布于:2023-07-18 08:00:34,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1086089.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:修改   源码   预测   保存
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图