torchvision pytorch预训练模型目标检测使用

参考:

https://pytorch.org/vision/0.13/models.html

https://blog.csdn.net/weixin_42357472/article/details/131747022

有分类、检测、分割相关预训练模型

1、目标检测

https://pytorch.org/vision/0.13/models.html#object-detection-instance-segmentation-and-person-keypoint-detection

matlab 复制代码
from torchvision.io.image import read_image
from torchvision.models.detection import fasterrcnn_resnet50_fpn_v2, FasterRCNN_ResNet50_FPN_V2_Weights
from torchvision.utils import draw_bounding_boxes
from torchvision.transforms.functional import to_pil_image


# Step 1: Initialize model with the best available weights
weights = FasterRCNN_ResNet50_FPN_V2_Weights.DEFAULT
model = fasterrcnn_resnet50_fpn_v2(weights=weights, box_score_thresh=0.9)
model.eval()



# Step 2: Initialize the inference transforms

img = read_image(r"C:\Users\loong\Downloads\people3.jpg")

preprocess = weights.transforms()

# Step 3: Apply inference preprocessing transforms
batch = [preprocess(img)]

# Step 4: Use the model and visualize the prediction
prediction = model(batch)[0]
labels = [weights.meta["categories"][i] for i in prediction["labels"]]
box = draw_bounding_boxes(img, boxes=prediction["boxes"],
                          labels=labels,
                          colors="red",
                          width=4, font_size=30)
im = to_pil_image(box.detach())
im.show()


微调代码finetuning 参考:

https://h-huang.github.io/tutorials/intermediate/torchvision_tutorial.html

https://www.youtube.com/watch?v=qC4yEiJOJtM

相关推荐
m0_587383006 分钟前
无人自助拼豆系统落地开发实战指南 核心逻辑实现与部署经验分享
前端·javascript·vue.js·人工智能·经验分享·需求分析
troy1288 分钟前
深度解析:如何用好 AI,成为自身能力的放大器
人工智能
ACP广源盛139246256739 分钟前
硬件选型笔记|国产 PCIe4.0 交换芯片 IX8012@ACP,边缘 AI 设备 IO 扩展方案探讨
人工智能·笔记·硬件架构·pcie·国产芯片
想会飞的蒲公英11 分钟前
Jev 模型详解:不生成文字的决策模型,接口、置信度与评测边界
人工智能·jev
虾..17 分钟前
计算机图形学:理解光照模型
人工智能
武子康19 分钟前
H3-World 的动作控制,为什么不能只靠一句提示词?
人工智能·agent
一木 之林20 分钟前
LangChain 第3章 消息与提示词模板:四类消息、历史管理与 ChatPromptTemplate
人工智能·计算机视觉·langchain
熊出没23 分钟前
AI Agent 生产级架构设计:工具调用与MCP、RAG、安全护栏与评估体系
人工智能·安全·架构设计·rag·ai agent
EEET智选23 分钟前
科技晨间速报 | AI 安全警钟、开源新模型与苹果智能家居
人工智能·科技·算法·机器学习·ai
CCblandy42 分钟前
Airllm 大模型本地化部署与高效推理应用指南
大数据·网络·人工智能