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 分钟前
我把大脑开源给了AI
人工智能·后端
Johny_Zhao2 小时前
OpenClaw安装部署教程
linux·人工智能·ai·云计算·系统运维·openclaw
飞哥数智坊2 小时前
我帮你读《一人公司(OPC)发展研究》
人工智能
冬奇Lab6 小时前
OpenClaw 源码精读(3):Agent 执行引擎——AI 如何「思考」并与真实世界交互?
人工智能·aigc
没事勤琢磨8 小时前
如何让 OpenClaw 控制使用浏览器:让 AI 像真人一样操控你的浏览器
人工智能
用户5191495848458 小时前
CrushFTP 认证绕过漏洞利用工具 (CVE-2024-4040)
人工智能·aigc
牛马摆渡人5288 小时前
OpenClaw实战--Day1: 本地化
人工智能
前端小豆8 小时前
玩转 OpenClaw:打造你的私有 AI 助手网关
人工智能
BugShare8 小时前
写一个你自己的Agent Skills
人工智能·程序员
机器之心9 小时前
英伟达护城河被AI攻破,字节清华CUDA Agent,让人人能搓CUDA内核
人工智能·openai