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

相关推荐
武子康5 分钟前
DeepSeek Harness 为什么不用 messages 数组保存一切
人工智能·llm·agent
bullkingluo7 分钟前
# 大模型意图识别翻车后,我们换掉了词典和分类 Prompt
人工智能
我是慎独9 分钟前
人工智能:现代方法读书笔记(十三)
人工智能·概率论
十三画者10 分钟前
【文献分享】KCFtools:基于k-mer的无比对基因组变异检测与基因型矩阵构建工具
人工智能·深度学习·数据挖掘·数据分析
m0_6380796213 分钟前
2026AI 论文工具测评:主流学术写作工具深度对比与避坑指南
人工智能
吃旺旺雪饼的小男孩13 分钟前
U-Net 语义分割详解:原论文、PyTorch 实现与真实消融实
人工智能·pytorch·python·算法
lucas_AI13 分钟前
35 种开源文档抽取配置,只有 4 个跨过 F1 0.5
人工智能·算法·llm
穿过生命散发芬芳14 分钟前
用 TRAE Work 把零散运维知识,系统化成一本可复用的运维红宝书
人工智能·trae
刘立军15 分钟前
中心化配置与 I18n:严格禁止 AI 魔法值与硬编码参数
人工智能·后端·架构
两万五千个小时21 分钟前
DeepSeek Harness 从 0 开始:18 todo 任务记忆
人工智能·程序员·架构