当前位置: 首页 > news >正文

MMSegmentation测试Segformer

#下载源码并解压缩

wget https://github.com/open-mmlab/mmsegmentation/archive/refs/tags/v1.2.1.tar.gz -O mmsegmentation-1.2.1.tar.gz
tar zxvf mmsegmentation-1.2.1.tar.gz

#安装mmcv

pip install mmcv==2.1.0

#安装openmim

pip3 install -U openmim

#安装其它依赖包

cd mmsegmentation-1.2.1
pip3 install -r requirements/runtime.txt
pip3 install -r requirements/tests.txt
pip3 install -r requirements/multimodal.txt
python setup.py develop -i https://pypi.tuna.tsinghua.edu.cn/simple


#下载配置文件和模型文件

mim download mmsegmentation --config segformer_mit-b2_8xb1-160k_cityscapes-1024x1024 --dest .

#测试SegFormer推理单张图片
 

python demo/image_demo.py demo/demo.png configs/segformer/segformer_mit-b2_8xb1-160k_cityscapes-1024x1024.py segformer_mit-b2_8x1_1024x1024_160k_cityscapes_20211207_134205-6096669a.pth --device cuda:0 --out-file result.jpg

#测试SegFormer推理多张图片

代码仿照demo/image_demo.py修改一下

import os
from glob import glob
from tqdm import tqdm
from argparse import ArgumentParser
from mmengine.model import revert_sync_batchnorm
from mmseg.apis import inference_model, init_model, show_result_pyplotdef main():parser = ArgumentParser()parser.add_argument('--input', help='Image file path')parser.add_argument('--config', help='Config file')parser.add_argument('--checkpoint', help='Checkpoint file')parser.add_argument('--output', help='Path to output file')parser.add_argument('--device', default='cuda:0', help='Device used for inference')parser.add_argument('--opacity',type=float,default=0.5,help='Opacity of painted segmentation map. In (0, 1] range.')parser.add_argument('--title', default='result', help='The image identifier.')args = parser.parse_args()# build the model from a config file and a checkpoint filemodel = init_model(args.config, args.checkpoint, device=args.device)if args.device == 'cpu':model = revert_sync_batchnorm(model)image_files = []if os.path.exists(args.input):if os.path.isdir(args.input):for ext in ['png', 'jpg', 'jpeg', 'bmp']:files = glob(os.path.join(args.input, '**/*.%s' % (ext)), recursive=True)if len(files) > 0:image_files.extend(files)else:returnif not os.path.exists(args.output):os.makedirs(args.output)for image_path in tqdm(image_files):(filename, extension) = os.path.splitext(image_path)filename = os.path.basename(filename)image_name = "result_" + filenameoutput_path = os.path.join(args.output, image_name + ".jpg")# process a single imageresult = inference_model(model, image_path)# show the resultsshow_result_pyplot(model,image_path,result,title=args.title,opacity=args.opacity,draw_gt=False,show=False,out_file=output_path)if __name__ == '__main__':main()

#推理测试一个文件夹下的所有图片

python demo/images_dir_demo.py --input demo/images --config configs/segformer/segformer_mit-b2_8xb1-160k_cityscapes-1024x1024.py --checkpoint segformer_mit-b2_8x1_1024x1024_160k_cityscapes_20211207_134205-6096669a.pth --device cuda:0 --output demo/result


http://www.mrgr.cn/news/20320.html

相关文章:

  • modelsim 关闭 warning 的方法
  • Java企业电子招投标系统:Spring Cloud微服务架构-强化企业招采竞争力:电子化招投标平台助力效率与成本控制-支持二次开发
  • 查看当前主机的硬盘是固态硬盘还是机械硬盘
  • TMGM:美国贸易逆差扩大将对第三季度GDP增长产生压力
  • 0.3 学习Stm32经历过的磨难
  • ROG STRIX Z790-E GAMING WIFI II
  • 【C语言】---- 复合数据类型之联合体(Union)
  • 【PostgreSQL教程】PostgreSQL 高级篇之 TRANSACTION(事务)
  • 体育数据API纳米足球数据API:足球数据接口文档API示例⑥
  • python socket TCP/UDP/MULTICAST 收发示例
  • Scratch在线玩:我的世界中文版
  • 云微客短视频矩阵系统多账号解析,打造流量新高地!
  • CSS选择器:一文带你区分CSS中的伪类和伪元素!
  • 微型丝杆工艺流程!
  • 如何选择适合的继电器测试负载箱?
  • c++ string中append/push_back/insert的区别以及erase/pop_back的区别
  • 外包干了2个月,技术退步明显了...
  • 基于Android Studio的行程记录APK开发指南(三)---界面设计及两种方法获取用户位置
  • 到底选哪个?伦敦银与黄金对比
  • Qt5控件模型工具类数据模型