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

相关推荐
野生面壁者章北海6 小时前
ICML2025|基于Logits的大语言模型端到端文本水印方法
人工智能·语言模型·自然语言处理
说私域6 小时前
开源AI智能名片链动2+1模式S2B2C商城小程序:分享经济时代的技术赋能与模式创新
人工智能·小程序·开源
HaiLang_IT7 小时前
基于深度学习的磁共振图像膝关节损伤多标签识别系统研究
人工智能·深度学习
月下倩影时7 小时前
视觉学习——卷积与神经网络:从原理到应用(量大管饱)
人工智能·神经网络·学习
思绪漂移7 小时前
CodeBuddy AI IDE:全栈AI开发平台实战
ide·人工智能·ai code
长空任鸟飞_阿康7 小时前
AI 多模态全栈应用项目描述
前端·vue.js·人工智能·node.js·语音识别
Mintopia7 小时前
🌐 实时协同 AIGC:多人在线 Web 创作的技术架构设计
前端·人工智能·trae
LaughingZhu7 小时前
Product Hunt 每日热榜 | 2025-11-14
人工智能·经验分享·搜索引擎·产品运营
Mintopia7 小时前
🔥 “Solo Coding”的近期热度解析(截至 2025 年末)
前端·人工智能·trae
pen-ai8 小时前
【高级机器学习】 10. 领域适应与迁移学习
人工智能·机器学习·迁移学习