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

相关推荐
云和数据.ChenGuang1 小时前
机器学习 分类算法
人工智能·机器学习·分类
古月居GYH3 小时前
3D Gaussian Splatting部分原理介绍和CUDA代码解读(一)——3D/2D协方差和高斯颜色的计算
人工智能·深度学习·3d
taoqick5 小时前
PyTorch DDP流程和SyncBN、ShuffleBN
人工智能·pytorch·python
Shockang5 小时前
机器学习的一百个概念(1)单位归一化
人工智能·机器学习
金融小师妹7 小时前
DeepSeek分析:汽车关税政策对黄金市场的影响评估
大数据·人工智能·汽车
仙尊方媛7 小时前
计算机视觉准备八股中
人工智能·深度学习·计算机视觉·视觉检测
MUTA️7 小时前
《Fusion-Mamba for Cross-modality Object Detection》论文精读笔记
人工智能·深度学习·目标检测·计算机视觉·多模态融合
qp8 小时前
18.OpenCV图像卷积及其模糊滤波应用详解
人工智能·opencv·计算机视觉
徐礼昭|商派软件市场负责人8 小时前
2025年消费观念转变与行为趋势全景洞察:”抽象、符号、游戏、共益、AI”重构新世代消费价值的新范式|徐礼昭
大数据·人工智能·游戏·重构·零售·中产阶级·消费洞察
訾博ZiBo8 小时前
AI日报 - 2025年03月31日
人工智能