代码拉取完成,页面将自动刷新
from PIL import Image
from utils import detect_image
import torch
from model import Unet_vgg
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
name_classes = ["background", "aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair",
"cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"]
model = Unet_vgg(num_classes=21, pretrained=True).to(device).eval()
checkpoint = torch.load('vgg_pretrain.pth')
model.load_state_dict(checkpoint)
img_path = './VOCdevkit/VOC2007/JPEGImages/2007_009052.jpg'
image = Image.open(img_path)
r_image = detect_image(model, image, device=device)
# r_image.show()
r_image.save('./predict.png')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。