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

相关推荐
知几蜗牛4 分钟前
本地语音AI不等于零风险:VoiceStudio最值得看的三条边界
人工智能
知几蜗牛4 分钟前
Claude接入十余种金融系统后,真正稀缺的是可追溯的审批链
人工智能
天远API11 分钟前
零信任架构实战:基于天远单人婚姻查询构建自动化联合贷款审计网关
java·人工智能·架构·自动化
远航计算机12 分钟前
网站被 AI 收录要多久?从被抓取到被引用的完整时间表
大数据·人工智能·aigc
昨日之日200615 分钟前
AuK:多任务语音生成编辑,支持克隆、改词、换情绪与分离,内容编辑与增强全覆盖
人工智能·音视频
知几蜗牛21 分钟前
4万星的Agent技能提醒我们:答案太全也可能不可用
人工智能
智购科技无人售货机工厂21 分钟前
2026自动售货机AI智能体架构:从47个小模型到33.7亿Token的工程实践~YH
android·人工智能·驱动开发·单片机·pandas
Geek-Chow23 分钟前
09. LLM 接缝:把“厂商协议“关进一个可替换的盒子
人工智能
麻瓜code23 分钟前
【Agent】从 0 手写智能体框架:ReAct + ToolCall 分层设计
人工智能·spring
来了就不要走28 分钟前
亿数平台怎么样:亿象生态与数实融合路径观察
大数据·人工智能·区块链