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

相关推荐
janeboe4 分钟前
抖音黑科技兵马俑总站源头简博科技 | 抖音锚点不合规挂载新规今日生效,短视频引流直播间迈入三端全链路监管时代
大数据·人工智能·科技
lialaka6 分钟前
「未来星途(Future_Odyssey)」——全语音_3D_AI_具身交互智能数字教官与全双工星际科普沉浸舱[1]
人工智能·3d·交互
hongmai6668887 分钟前
ESP32-C61-WROOM-1-N8R2:Wi-Fi 6与RISC-V融合的中坚力量
人工智能·单片机·嵌入式硬件·物联网·智能家居·risc-v
正在走向自律11 分钟前
用豆包Seed Evolving打造全功能【AI智能记账】小程序,开源可落地
人工智能·小程序·开源·智能记账
小保CPP18 分钟前
OpenCV C++提取webp动图里的图片
c++·人工智能·opencv·计算机视觉
B8017913Y19 分钟前
手动整理录音太慢错漏多?2026专业AI录音可高效整理内容
人工智能
梦想的颜色21 分钟前
AI Agent 可观测性:破解多步推理黑盒|从概念、架构、指标到生产落地图鉴
人工智能·ai agent 可观测性·llm 追踪 trace·llmops 硬核实战·agent 生产运维
IT智慧客073124 分钟前
Harness 到底指什么
人工智能
大模型任我行32 分钟前
阿里:端到端文档解析模型OvisOCR2
人工智能·语言模型·自然语言处理·论文笔记
aixingkong92134 分钟前
Atlas 950 1024卡SuperPoD推测分析
网络·人工智能·硬件架构·硬件工程