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

相关推荐
却道天凉_好个秋7 分钟前
深度学习(四):数据集划分
人工智能·深度学习·数据集
数字冰雹11 分钟前
“图观”端渲染场景编辑器
人工智能·编辑器
里昆11 分钟前
【AI】Tensorflow在jupyterlab中运行要注意的问题
人工智能·python·tensorflow
荼蘼32 分钟前
OpenCV 高阶 图像金字塔 用法解析及案例实现
人工智能·opencv·计算机视觉
Clownseven34 分钟前
2025云计算趋势:Serverless与AI大模型如何赋能中小企业
人工智能·serverless·云计算
2401_8288906436 分钟前
使用 BERT 实现意图理解和实体识别
人工智能·python·自然语言处理·bert·transformer
Cheney8221 小时前
华为Ai岗机考20250903完整真题
人工智能·华为
新智元1 小时前
=COPILOT() 函数横空出世!AI 自动写公式效率起飞,网友:让 Excel 再次伟大
人工智能·openai
scx_link1 小时前
Word2Vec词嵌入技术和动态词嵌入技术
人工智能·自然语言处理·word2vec
云梦谭1 小时前
Cursor 编辑器:面向 AI 编程的新一代 IDE
ide·人工智能·编辑器