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

相关推荐
翻滚的小@强2 分钟前
自动驾驶科普(百度Apollo)学习笔记
人工智能·自动驾驶·百度apollo
从零开始学习人工智能2 分钟前
从游戏到自动驾驶:互联网时代强化学习如何让机器学会自主决策?
人工智能·游戏·自动驾驶
幼稚园的山代王17 分钟前
Prompt Enginering(提示工程)先进技术
java·人工智能·ai·chatgpt·langchain·prompt
dfsj6601118 分钟前
LLMs 系列科普文(14)
人工智能·深度学习·算法
摘取一颗天上星️24 分钟前
深入解析机器学习的心脏:损失函数及其背后的奥秘
人工智能·深度学习·机器学习·损失函数·梯度下降
远方160931 分钟前
20-Oracle 23 ai free Database Sharding-特性验证
数据库·人工智能·oracle
znhy605833 分钟前
智能终端与边缘计算按章复习
人工智能·边缘计算
__Benco39 分钟前
OpenHarmony平台驱动使用(十五),SPI
人工智能·驱动开发·harmonyos
Listennnn40 分钟前
AI系统的构建
人工智能·系统架构
新智元43 分钟前
全球 30 名顶尖数学家秘密集会围剿 AI,当场破防!惊呼已接近数学天才
人工智能·openai