代码拉取完成,页面将自动刷新
同步操作将从 Lonng/YOLOv8_Segment 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
'''
Description:
version:
Author: aps.auto
Date: 2024-06-26 11:39:40
LastEditors: Luoxl
LastEditTime: 2024-07-02 08:41:26
'''
from ultralytics import YOLO
import ultralytics
import torch
import numpy as np
import os
import cv2
def extract_masks(result, target_class):
masks = []
labels_index = result.boxes.cls.data.numpy()
for i, index in enumerate(labels_index):
if result.names[index] == target_class:
masks.append(np.squeeze(result.masks[i].data.numpy())>0)
return masks
import time
import glob
# Load a model
model = ultralytics.YOLO("yolov8n-seg.pt") # load an official model
model = ultralytics.YOLO("D:/BaiduSyncdisk/Projects/yolov8-segment/yolov8n-seg-AGI.pt") # load a custom model
# 推理预热
input = torch.randn((1, 3, 480, 640))
model.predict(input)
# result = model.export(format='onnx') #yolov8原生转换
t1 = time.time()
model.predict('test.png')
print(f"总耗时{(time.time()-t1)*1000}ms")
# source = "D:/BaiduSyncdisk/Projects/yolov8-segment/robot_seg_dataset/images/test"
# png_files = glob.glob(os.path.join(source, '*.png'))
# print(f"共计 {len(png_files)}张图像")
# t1 = time.time()
# results = model.predict(source) # predict on an image
# print('ok')
# masks = extract_masks(results[0], "cell phone")
# mask = masks[0].astype(np.uint8)
# output = np.repeat(mask[:, :, np.newaxis], 3, axis=2)*255
# cv2.imwrite('output_mask.png', output)
# t2 = time.time()
# print(f"总耗时{(t2-t1)*1000}ms")
# print(f"推理一张图像耗时{1000*(t2-t1)/len(png_files)}ms")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。