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

相关推荐
H Journey5 分钟前
openCV图像学-二值化
人工智能·opencv·计算机视觉
算法即正义5 分钟前
知识竞赛计分规则设置指南:七种计分模式详解与实操建议
人工智能
这张生成的图像能检测吗9 分钟前
(论文速读)基于微调大语言模型的数控车床故障诊断
人工智能·语言模型·故障诊断·车床技术
大写-凌祁9 分钟前
RescueADI:基于自主智能体的遥感图像自适应灾害解译
人工智能·计算机视觉·语言模型·自然语言处理·aigc
fof92013 分钟前
Base LLM | 从 NLP 到 LLM 的算法全栈教程 第六天
人工智能·自然语言处理
Godspeed Zhao17 分钟前
科技信息最前沿——TurboQuant:以极致压缩重新定义人工智能效率
人工智能·科技
AI医影跨模态组学19 分钟前
Radiology子刊(IF=6.3)复旦大学附属金山医院强金伟教授等团队:基于多参数MRI的深度学习和影像组学评估早期宫颈癌淋巴结转移
人工智能·深度学习·论文·医学·医学影像
Ln5x9qZC220 分钟前
Laravel AI SDK 正式发布
android·人工智能·laravel
nimadan1221 分钟前
生成剧本杀软件2025推荐,创新剧情设计工具引领潮流
人工智能·python
嵌入式小企鹅24 分钟前
阿里编程模型赶超、半导体涨价蔓延、RISC-V新品密集上线
人工智能·学习·ai·程序员·risc-v·芯片