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

相关推荐
数字游民95272 分钟前
网站备案全流程回放(腾讯云)
人工智能·git·github·腾讯云·网站备案·waytoopc
飞哥数智坊5 分钟前
3位实战分享、6个案例展示,TRAE Friends@济南第二场圆满完成
人工智能·ai编程·trae
xiaobaishuoAI6 分钟前
全链路性能优化实战指南:从瓶颈定位到极致优化
大数据·人工智能·科技·百度·geo
人工小情绪6 分钟前
深度学习模型部署形式
人工智能·深度学习
AI_56788 分钟前
零基础学Linux:21天从“命令小白”到独立部署服务器
linux·服务器·人工智能·github
乾元10 分钟前
如何把 CCIE / HCIE 的实验案例改造成 AI 驱动的工程项目——从“实验室能力”到“可交付系统”的完整迁移路径
大数据·运维·网络·人工智能·深度学习·安全·机器学习
kisshuan1239610 分钟前
【深度学习】【目标检测】基于Mask R-CNN的鱼类尾巴检测与识别
深度学习·目标检测·r语言
GZKPeng11 分钟前
pytorch +cuda成功安装后, torch.cuda.is_available 是False
人工智能·pytorch·python
QBoson14 分钟前
量子机器学习用于药物发现:系统综述
人工智能·机器学习·量子计算
DatGuy14 分钟前
Week 32: 深度学习补遗:Agent的认知架构、记忆系统与高阶规划
人工智能·深度学习