首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用.pt文件分析图像

使用.pt文件分析图像
EN

Stack Overflow用户
提问于 2022-10-18 22:45:26
回答 1查看 80关注 0票数 0

我是AI的新手,对我能做的概念错误感到很抱歉。我确实有一个.pt文件,我想用它来获取一些图片的边框。最简单的方法是什么?类似于:

代码语言:javascript
复制
import torch
model=torch.load('best.pt')
img=['foto.jpg']
results = model(img)
results.show()

非常感谢!

EN

回答 1

Stack Overflow用户

发布于 2022-10-18 22:48:46

使用

代码语言:javascript
复制
Syntax – torch.utils.draw_bounding_boxes(image, box)

Parameter:

image: Tensor of shape (C x H x W) 
box: Bounding boxes size in (xmin, ymin, xmax, ymax).
Return: Image Tensor of dtype uint8 with bounding boxes plotted.
代码语言:javascript
复制
# Import the required libraries
import torch
import torchvision
from torchvision.io import read_image
from torchvision.utils import draw_bounding_boxes

# read input image from your computer
img = read_image('a3.pt')

# bounding box are xmin, ymin, xmax, ymax
box = [330, 190, 660, 355]
box = torch.tensor(box)
box = box.unsqueeze(0)

# draw bounding box and fill color
img = draw_bounding_boxes(img, box, width=5,
                        colors="green",
                        fill=True)

# transform this image to PIL image
img = torchvision.transforms.ToPILImage()(img)

# display output
img.show()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74118204

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档