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

相关推荐
overstarry4 分钟前
Goland 通过 ACP 连接 Claude Code
人工智能·claude·jetbrains
overstarry4 分钟前
Midscene.js 初尝试
人工智能·llm
weixin_457760004 分钟前
GIOU (Generalized Intersection over Union) 详解
pytorch·python
ZouZou老师6 分钟前
AI时代架构师如何重构研发体系
人工智能
小魔女千千鱼7 分钟前
openEuler AI 开发环境搭建 - Python/Anaconda/Jupyter 完整指南
人工智能
凌晨一点的秃头猪9 分钟前
seed随机种子
人工智能
ChatPPT_YOO9 分钟前
AIPPT工具主题生成深度对比:为什么ChatPPT更胜一筹?
人工智能·信息可视化·powerpoint·ai生成ppt·ppt制作
糖葫芦君10 分钟前
OneRec - V2 lazy decoder为什么效率高
人工智能·深度学习·llm
轻竹办公PPT11 分钟前
学校要求开题报告 PPT,有没有模板?
人工智能·python·powerpoint
大雾的小屋20 分钟前
【1-1】基于深度学习的滚动轴承故障诊断系统:从数据处理到交互式界面全流程解析
人工智能·pytorch·深度学习·系统架构·人机交互·pyqt·用户界面