开源预训练框架 MMPRETRAIN现有的推理模型(三)

news2024/9/24 21:26:25

推理器类型:

(1)ImageClassificationInferencer:对给定图像进行图像分类。
(2)ImageRetrievalInferencer:从给定图像集上的给定图像执行图像到图像检索。
(3)ImageCaptionInferencer:在给定图像上生成标题
(4)VisualQuestionAnsweringInferencer:根据给定的图片回答问题。
(5)VisualGroundingInferencer:从给定图像的描述中找到一个对象。
(6)TextToImageRetrievalInferencer:根据给定图像集的给定描述执行文本到图像检索。
(7)ImageToTextRetrievalInferencer:从给定图像对一系列文本执行图像到文本检索。
(8)NLVRInferencer:对给定的图像对和文本执行自然语言视觉推理。
(9)FeatureExtractor:通过视觉主干从图像文件中提取特征。

列出可用型号

列出 MMPreTrain 中的所有模型。

from mmpretrain import list_models
list_models()#目前共有539个模型

在这里插入图片描述

可用型号搜索

list_models支持Unix文件名模式匹配,可以使用*** * **来匹配任何字符。

from mmpretrain import list_models
list_models("*convnext-b*21k")

在这里插入图片描述

获取相应任务的可用模型

您可以使用list_models推理器的方法来获取相应任务的可用模型。

1、Get a model

you can use get_model get the model.

from mmpretrain import get_model
model = get_model("convnext-base_in21k-pre_3rdparty_in1k")
model = get_model("convnext-base_in21k-pre_3rdparty_in1k", pretrained=True)
model = get_model("convnext-base_in21k-pre_3rdparty_in1k", pretrained="your_local_checkpoint_path")
model = get_model("convnext-base_in21k-pre_3rdparty_in1k", head=dict(num_classes=10))
model_headless = get_model("resnet18_8xb32_in1k", head=None, neck=None, backbone=dict(out_indices=(1, 2, 3)))

获得的模型是常用的 PyTorch 模块

import torch
from mmpretrain import get_model
model = get_model('convnext-base_in21k-pre_3rdparty_in1k', pretrained=True)
x = torch.rand((1, 3, 224, 224))
y = model(x)
print(type(y), y.shape)

2、ImageClassificationInferencer:对给定图像进行图像分类任务可用模型

from mmpretrain import ImageClassificationInferencer
ImageClassificationInferencer.list_models()

在这里插入图片描述

1、通过inference_model进行任务推理

from mmpretrain import list_models, inference_model
list_models('resnet50', task='Image Classification')#给定任务和骨干网络预训练模型
inference_model('resnet50_8xb32_in1k', '/media/lhy/mmpretrain/demo/bird.JPEG', show=True)#给定预训练模型和图像的路径

在这里插入图片描述

2、通过ImageClassificationInferencer进行任务推理

该inference_model API仅用于演示,不能保留模型实例或对多个样本进行推理。您可以使用推理器进行多次调用。

1. 使用MMPreTrain中的预训练模型对图像进行推理。

from mmpretrain import  list_models, ImageClassificationInferencer
image = '/media/lhy/mmpretrain/demo/bird.JPEG'
inferencer = ImageClassificationInferencer('resnet50_8xb32_in1k')
# Note that the inferencer output is a list of result even if the input is a single sample.
result = inferencer(image)[0]
print(result['pred_class'])
print(result['pred_score'])
print(result['pred_label'])
# You can also use is for multiple images.
image_list = ['demo/demo.JPEG', 'demo/bird.JPEG'] * 16
results = inferencer(image_list, batch_size=8)
print(len(results))
print(results[1]['pred_class'])

2. 使用配置文件和检查点来推断GPU上的多个图像,并将可视化结果保存在文件夹中。

from mmpretrain import ImageClassificationInferencer
inferencer = ImageClassificationInferencer(model='configs/resnet/resnet50_8xb32_in1k.py',
pretrained='https://download.openmmlab.com/mmclassification/v0/resnet/resnet50_8xb32_in1k_20210831-ea4938fc.pth',device='cuda')
inferencer(['demo/dog.jpg', 'demo/bird.JPEG'], show_dir="./visualize/")

visualize_kwargs: set = {
      'resize', 'rescale_factor', 'draw_score', 'show', 'show_dir',
      'wait_time'
  }

3、gradio 演示进行任务推理

在这里插入图片描述

3、ImageRetrievalInferencer:从给定图像集上的给定图像执行图像到图像检索

from mmpretrain import ImageRetrievalInferencer
ImageRetrievalInferencer.list_models()

在这里插入图片描述

2、通过ImageRetrievalInferencer进行任务推理

from mmpretrain import list_models,ImageRetrievalInferencer
inferencer = ImageRetrievalInferencer('resnet50-arcface_inshop',prototype=['/media/lhy/mmpretrain/demo/demo.JPEG', '/media/lhy/mmpretrain/demo/dog.jpg'],prototype_cache='img_retri.pth')
#prototype检索的图像列表
inferencer('/media/lhy/mmpretrain/demo/cat-dog.png', topk=2)[0][1]

{'match_score': tensor(0.4088, device='cuda:0'),
   'sample_idx': 3,
   'sample': {'img_path': './demo/dog.jpg'}}
"""  # noqa: E501

visualize_kwargs: set = {
  'draw_score', 'resize', 'show_dir', 'show', 'wait_time', 'topk'
}
postprocess_kwargs: set = {'topk'}

在这里插入图片描述

4、ImageCaptionInferencer(在给定图像上生成标题)任务可用模型

from mmpretrain import ImageCaptionInferencer
ImageCaptionInferencer.list_models()
['blip-base_3rdparty_caption',
'blip2-opt2.7b_3rdparty-zeroshot_caption', 
'flamingo_3rdparty-zeroshot_caption', 
'llava-7b-v1_caption',
'minigpt-4_vicuna-7b_caption',
'ofa-base_3rdparty-finetuned_caption', 
'otter-9b_3rdparty_caption']

1、通过inference_model进行任务推理

from mmpretrain import list_models, inference_model
list_models(task='Image Caption') #给定任务和骨干网络预训练模型
inference_model('ofa-base_3rdparty-finetuned_caption', '/media/lhy/mmpretrain/demo/cat-dog.png', show=True)

在这里插入图片描述

2、通过ImageCaptionInferencer进行任务推理

from mmpretrain import ImageCaptionInferencer
inferencer = ImageCaptionInferencer('blip-base_3rdparty_caption')
inferencer('/media/lhy/mmpretrain/demo/cat-dog.png')[0]

{'pred_caption': 'a puppy and a cat sitting on a blanket'}

5、VisualGroundingInferencer:从给定图像的描述中找到一个对象任务可用模型

from mmpretrain import VisualGroundingInferencer
VisualGroundingInferencer.list_models()

[‘blip-base_8xb16_refcoco’, ‘ofa-base_3rdparty-finetuned_refcoco’]

在这里插入图片描述

1、通过inference_model进行任务推理

from mmpretrain import list_models, inference_model
list_models(task='Visual Grounding') #给定任务和骨干网络预训练模型
inference_model('ofa-base_3rdparty-finetuned_refcoco', '/media/lhy/mmpretrain/demo/cat-dog.png', 'cat', show=True)

2、通过ImageCaptionInferencer进行任务推理

from mmpretrain import VisualGroundingInferencer
inferencer = VisualGroundingInferencer('ofa-base_3rdparty_refcocinferencer('/media/lhy/mmpretrain/demo/cat-dog.png', 'dog')[0]
{'pred_bboxes': tensor([[ 36.6000,  29.6000, 355.8000, 395.2000]])}
    """  # noqa: E501

6、TextToImageRetrievalInferencer:(根据给定图像集的给定描述执行文本到图像检索)任务可用模型

from mmpretrain import TextToImageRetrievalInferencer
TextToImageRetrievalInferencer.list_models()
['blip-base_3rdparty_retrieval', 'blip2_3rdparty_retrieval']

在这里插入图片描述

1、通过TextToImageRetrievalInferencer进行任务推理

from mmpretrain import TextToImageRetrievalInferencer
inferencer = TextToImageRetrievalInferencer('blip-base_3rdparty_retrieval',prototype='/media/lhy/mmpretrain/demo/',prototype_cache='t2i_retri.pth')
inferencer('A cat and a dog.')[0]

{'match_score': tensor(0.3855, device='cuda:0'),
		        'sample_idx': 1,
		        'sample': {'img_path': './demo/cat-dog.png'}}

在这里插入图片描述

7、ImageToTextRetrievalInferencer(从给定图像对一系列文本执行图像到文本检索)

from mmpretrain import ImageToTextRetrievalInferencer
ImageToTextRetrievalInferencer.list_models()

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/798266.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

FS32K144用官方Bootloader为底层用RAppIDL BL Tool工具下载升级程序

​​​​​​​ ​​​​​​​ ​​​​​​​ ​​​​​​​ ​​​​​​​ 一、工具问题 1、可以在NXP的官网上找到这个软件,也可以加载完成NXP的官方库后找到它(自动安装的),也可我…

【接口测试】Postman--变量与集合

目录 变量与集合 一、变量 1、环境变量(1)创建环境变量(2)管理环境变量(3)选择与编辑环境变量2、全局变量(1)管理全局变量二、集合 1、创建集合2、保存请求到集合3、分享集合三、集…

链表是否有环、环长度、环起点

问题引入 如何检测一个链表是否有环,如果有,那么如何确定环的长度及起点。 引自博客:上述问题是一个经典问题,经常会在面试中被问到。我之前在杭州一家网络公司的电话面试中就很不巧的问到,当时是第一次遇到那个问题&…

【数据结构】实验一:绪论

实验一 绪论 一、实验目的与要求 1)熟悉C/C语言(或其他编程语言)的集成开发环境; 2)通过本实验加深对算法时间复杂度的理解; 3)结合具体的问题分析算法时间复杂度。 二、实验内容 设计程…

C# PaddleDetection 目标检测 ( yolov3_darknet)

效果 项目 VS2022.net4.8OpenCvSharp4Sdcb.PaddleDetection 代码 using OpenCvSharp; using OpenCvSharp.Extensions; using Sdcb.PaddleDetection; using Sdcb.PaddleInference; using System; using System.Drawing; using System.Windows.Forms; using YamlDotNet;namespa…

vue实现循环数据动态添加标签以及单独控制显示隐藏

效果图&#xff1a; html: <table class"tag-table"><tbody><tr v-for"(item, index) in form.tagList" :key"index"><td>333</td><td><divclass"tag-box"v-for"(item1, index1) in it…

推荐用于学习RN原生模块开发的开源库—react-native-ble-manager

如题RN的原生模块/Native Modules的开发是一项很重要的技能&#xff0c;但RN官网的示例又比较简单&#xff0c;然后最近我接触与使用、还有阅读了react-native-ble-manager的部份源码&#xff0c;发现里边完全包含了一个Native Modules所涉及的知识点/技术点&#xff0c;故特推…

【SAM MaskDecoder 图】SAM(segment anything) 中MaskDecoder过程图示

SAM(segment anything) 中MaskDecoder过程图示 本人根据代码画的&#xff0c;如有出入&#xff0c;欢迎留言反馈更正。

算法之归并排序算法

归并&#xff08;Merge&#xff09;排序法是将两个&#xff08;或两个以上&#xff09;有序表合并成一个新的有序表&#xff0c;即把待排序序列 分为若干个子序列&#xff0c;每个子序列是有序的。然后再把有序子序列合并为整体有序序列。 public class MergeSortTest {public …

简单上手FineBI

简介 安装下载 下载的是V6.0.11版本 设置管理员账号 账号admin 密码123456 新建分析主题 添加数据 选择本地数据上传 选择示例数据上传 打开效果如下&#xff0c;点击“确定”&#xff0c;这样就将示例数据上传到分析主题中 分析数据——编辑数据 如果数据质量好&#xf…

用OpenCV图像处理技巧之白平衡算法(二)

1. 引言 在上一节中我们介绍了白平衡算法的原理&#xff0c;并详细实现了基于白色补丁算法的白平衡实现&#xff0c;本文继续就白平衡的其他算法实现进行展开。 闲话少说&#xff0c;我们直接开始吧&#xff01; 2. Gray-world Algorithm 灰色世界算法&#xff08;Gray-wor…

protobuf安装教程

protobuf安装 一&#xff0c;Windows下安装下载protobuf配置环境变量检查是否安装成功 二&#xff0c;Linux下安装下载protobuf安装protobuf检查是否安装成功 一&#xff0c;Windows下安装 下载protobuf 下载地址 本次下载以v21.11为例&#xff0c;根据自己需求下载即可。 配…

VL163的基本信息

VL163是2:4差分通道多路复用/demux开关USB 3.1应用&#xff0c;为交换机信号性能支持高达USB 3.1&#xff0c;并使用QFN-28 3.5x4.5mm绿色封装。 VL163 QFN28 只能处理2Lane数据信号。自己没有CC识别沟通协议&#xff0c;如果要做USB-C Swtich&#xff0c;就要通过别的USB-C协…

Python计算统计分析MSE 、RMSE、MAE、R2

1、平均绝对误差 (MAE)Mean Absolute Error&#xff0c;是绝对误差的平均值&#xff0c;能更好地反映预测值误差的实际情况。范围[0,∞)&#xff0c;当预测值与真实值完全吻合时等于0&#xff0c;即完美模型&#xff1b;误差越大&#xff0c;该值越大。 2、均方误差 MSE(mean…

团簇大小分布计算方法,fix ave/histo命令详解

LAMMPS是一款广泛应用于分子动力学模拟的强大软件。在模拟过程中&#xff0c;我们经常需要对系统的物理性质进行分析和统计。 fix ave/histo命令则是LAMMPS中一个非常有用的命令&#xff0c;它可以帮助我们对系统进行直方图统计分析。 本文将深入介绍fix ave/histo命令的用法和…

CentOS 搭建 GitLab Git

本文目录 1. CentOS7 搭建 Gitlab1. 安装 sshd1. 安装 sshd 依赖2. 启动并设置开机自启3. 安装防火墙4. 开启防火墙5. 开放 ssh 以及 http 服务 2. 安装 postfix1. 安装 postfix2. 启动并设置开机自启3. 几个补充知识 3. 下载并安装 gitlab1. 在线下载安装包2. 安装 4. 修改 gi…

保障大文件传输数据完整性的策略探讨

随着互联网技术的快速发展&#xff0c;越来越多的文件需要进行传输。而在大文件传输中&#xff0c;数据完整性尤为重要&#xff0c;因为数据一旦丢失或损坏&#xff0c;将对文件的可用性和可靠性产生负面影响。因此&#xff0c;保障大文件传输数据完整性成为了互联网技术领域中…

基于java的坦克大战游戏的设计与实现--毕业论文--【毕业论文】

文章目录 本系列校训毕设的技术铺垫文章主体层次摘要&#xff1a;示例摘要的写法 引言&#xff1a;系统分析总体设计总体功能总体功能如图1所示坦克大战总体流程图 详细设计游戏测试结论参考文献参考文献 配套资源 本系列校训 互相伤害互相卷&#xff0c;玩命学习要你管&#…

DoIP学习笔记系列:(二)VN5620 DoIP测试配置实践笔记

文章目录 1. 添加.cdd2. CAPL中调用接口发送DoIP请求3. “Ethernet Packet Builder”的妙用4. CANoe也可以做交互界面在进行测试前,先检查车载以太网硬件连线是否正确,需要注意连接两端的Master、Slave,100M、1000M等基本情况,在配置VN5620的时候就可以灵活处理了。成功安装…

FTP服务器的搭建和配置上传脚本

文章目录 前言一、配置本地用户可上传权限ftp服务器1、用户登录ftp 二、配置FTP上传脚本文件1.脚本代码如下 补充知识 前言 vsftpd&#xff08;Very Secure FTP Daemon&#xff09;是一个在 Linux/Unix 系统上运行的一款开源免费的 FTP 服务器软件。vsftpd 支持支持 匿名用户、…