我是AI的新手,对我能做的概念错误感到很抱歉。我确实有一个.pt文件,我想用它来获取一些图片的边框。最简单的方法是什么?类似于:
import torch
model=torch.load('best.pt')
img=['foto.jpg']
results = model(img)
results.show()非常感谢!
发布于 2022-10-18 22:48:46
使用
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.# 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()https://stackoverflow.com/questions/74118204
复制相似问题