测试"/>
Yolov8之部署测试
Y o l o v 8 之部署测试 Yolov8之部署测试 Yolov8之部署测试
- 1.部署测试-分类模型
- 2.部署测试-检测模型
- 3.部署测试-分割模型
1.部署测试-分类模型
1.1 测试模型-cpu
from ultralytics import YOLO
import datetime
# 模型路径
model_path = r"D:\YoloV8Manual\AIModel\CatAndDog_Cls\weights\best.pt"
# 预测图像
predict_ImgPath = r"D:\YoloV8Manual\dataset\DogCat-cls\train\dog\0002.png"
# 输入模型图像大小
imgsz = 224
# 加载模型
model = YOLO(model_path)
# 模型预测
for i in range(100):# 开始计时startTime = datetime.datetime.now()# 模型预测results = model.predict(source=predict_ImgPath, imgsz=imgsz ,save=False,device="cpu") # save plotted images# 结束计时endTime = datetime.datetime.now()# 计算耗时durTime = '模型推理时间:%dms' % ((endTime - startTime).seconds * 1000 + (endTime - startTime).microseconds / 1000)# 打印耗时print(durTime)
1.2 测试模型-gpu
from ultralytics import YOLO
import datetime
# 模型路径
model_path = r"D:\YoloV8Manual\AIModel\CatAndDog_Cls\weights\best.pt"
# 预测图像
predict_ImgPath = r"D:\YoloV8Manual\dataset\DogCat-cls\train\dog\0002.png"
# 输入模型图像大小
imgsz = 224
# 加载模型
model = YOLO(model_path)
# 模型预测
for i in range(100):# 开始计时startTime = datetime.datetime.now()# 模型预测results = model.predict(source=predict_ImgPath, imgsz=imgsz ,save=False) # save plotted images# 结束计时endTime = datetime.datetime.now()# 计算耗时durTime = '模型推理时间:%dms' % ((endTime - startTime).seconds * 1000 + (endTime - startTime).microseconds / 1000)# 打印耗时print(durTime)
2.部署测试-检测模型
1.1 测试模型-cpu
from ultralytics import YOLO
import datetime
import cv2
# 模型路径
model_path = r"D:\YoloV8Manual\AIModel\CatAndDog_Det\weights\best.pt"
# 预测图像
predict_ImgPath = r"D:\YoloV8Manual\dataset\DogCat-det\images\train\2.jpg"
# 输入模型图像大小
imgsz = 224
# 加载模型
model = YOLO(model_path)
# 模型预测
for i in range(100):# 开始计时startTime = datetime.datetime.now()# 模型预测# img = cv2.imread(predict_ImgPath)results = model.predict(source=predict_ImgPath,imgsz=imgsz,device='cpu') # save plotted images# 结束计时endTime = datetime.datetime.now()# 计算耗时durTime = '模型推理时间:%dms' % ((endTime - startTime).seconds * 1000 + (endTime - startTime).microseconds / 1000)# 打印耗时print(durTime)
1.2 测试模型-gpu
from ultralytics import YOLO
import datetime
import cv2
# 模型路径
model_path = r"D:\YoloV8Manual\AIModel\CatAndDog_Det\weights\best.pt"
# 预测图像
predict_ImgPath = r"D:\YoloV8Manual\dataset\DogCat-det\images\train\2.jpg"
# 输入模型图像大小
imgsz = 224
# 加载模型
model = YOLO(model_path)
# 模型预测
for i in range(100):# 开始计时startTime = datetime.datetime.now()# 模型预测# img = cv2.imread(predict_ImgPath)results = model.predict(source=predict_ImgPath,imgsz=imgsz) # save plotted images# 结束计时endTime = datetime.datetime.now()# 计算耗时durTime = '模型推理时间:%dms' % ((endTime - startTime).seconds * 1000 + (endTime - startTime).microseconds / 1000)# 打印耗时print(durTime)
1.3 测试模型-openvino
from ultralytics import YOLO
import datetime
import cv2
# 模型路径
model_path = r"D:\YoloV8Manual\AIModel\CatAndDog_Det\weights\best_openvino_model"
# 预测图像
predict_ImgPath = r"D:\YoloV8Manual\dataset\DogCat-det\images\train\2.jpg"
# 输入模型图像大小
imgsz = 224
# 加载模型
model = YOLO(model_path)
# 模型预测
for i in range(100):# 开始计时startTime = datetime.datetime.now()# 模型预测# img = cv2.imread(predict_ImgPath)results = model.predict(source=predict_ImgPath,imgsz=imgsz,device='cpu') # save plotted images# 结束计时endTime = datetime.datetime.now()# 计算耗时durTime = '模型推理时间:%dms' % ((endTime - startTime).seconds * 1000 + (endTime - startTime).microseconds / 1000)# 打印耗时print(durTime)
1.4 测试模型-TensorRT
from ultralytics import YOLO
import datetime
import cv2
# 模型路径
model_path = r"D:\YoloV8Manual\AIModel\CatAndDog_Det\weights\best.engine"
# 预测图像
predict_ImgPath = r"D:\YoloV8Manual\dataset\DogCat-det\images\train\2.jpg"
# 输入模型图像大小
imgsz = 224
# 加载模型
model = YOLO(model_path)
# 模型预测
for i in range(100):# 开始计时startTime = datetime.datetime.now()# 模型预测# img = cv2.imread(predict_ImgPath)results = model.predict(source=predict_ImgPath,imgsz=imgsz) # save plotted images# 结束计时endTime = datetime.datetime.now()# 计算耗时durTime = '模型推理时间:%dms' % ((endTime - startTime).seconds * 1000 + (endTime - startTime).microseconds / 1000)# 打印耗时print(durTime)
3.部署测试-分割模型
1.1 测试模型-cpu
from ultralytics import YOLO
import datetime
import cv2
# 模型路径
model_path = r"D:\YoloV8Manual\yolov8s-seg.pt"
# 预测图像
predict_ImgPath = r"D:\YoloV8Manual\dataset\DogCat-seg\images\train\2.jpg"
# 输入模型图像大小
imgsz = 224
# 加载模型
model = YOLO(model_path)
# 模型预测
for i in range(100):# 开始计时startTime = datetime.datetime.now()# 模型预测# img = cv2.imread(predict_ImgPath)results = model.predict(source=predict_ImgPath,imgsz=imgsz,device='cpu') # save plotted images# 结束计时endTime = datetime.datetime.now()# 计算耗时durTime = '模型推理时间:%dms' % ((endTime - startTime).seconds * 1000 + (endTime - startTime).microseconds / 1000)# 打印耗时print(durTime)
1.2 测试模型-gpu
from ultralytics import YOLO
import datetime
import cv2
# 模型路径
model_path = r"D:\YoloV8Manual\yolov8s-seg.pt"
# 预测图像
predict_ImgPath = r"D:\YoloV8Manual\dataset\DogCat-seg\images\train\2.jpg"
# 输入模型图像大小
imgsz = 224
# 加载模型
model = YOLO(model_path)
# 模型预测
for i in range(100):# 开始计时startTime = datetime.datetime.now()# 模型预测# img = cv2.imread(predict_ImgPath)results = model.predict(source=predict_ImgPath,imgsz=imgsz) # save plotted images# 结束计时endTime = datetime.datetime.now()# 计算耗时durTime = '模型推理时间:%dms' % ((endTime - startTime).seconds * 1000 + (endTime - startTime).microseconds / 1000)# 打印耗时print(durTime)
1.3 测试模型-openvino
from ultralytics import YOLO
import datetime
import cv2
# 模型路径
model_path = r"D:\YoloV8Manual\yolov8s-seg_openvino_model"
# 预测图像
predict_ImgPath = r"D:\YoloV8Manual\dataset\DogCat-seg\images\train\2.jpg"
# 输入模型图像大小
imgsz = 224
# 加载模型
model = YOLO(model_path)
# 模型预测
for i in range(100):# 开始计时startTime = datetime.datetime.now()# 模型预测# img = cv2.imread(predict_ImgPath)results = model.predict(source=predict_ImgPath,imgsz=imgsz,device='cpu') # save plotted images# 结束计时endTime = datetime.datetime.now()# 计算耗时durTime = '模型推理时间:%dms' % ((endTime - startTime).seconds * 1000 + (endTime - startTime).microseconds / 1000)# 打印耗时print(durTime)
1.4 测试模型-TensorRT
from ultralytics import YOLO
import datetime
import cv2
# 模型路径
model_path = r"D:\YoloV8Manual\yolov8s-seg.engine"
# 预测图像
predict_ImgPath = r"D:\YoloV8Manual\dataset\DogCat-seg\images\train\2.jpg"
# 输入模型图像大小
imgsz = 224
# 加载模型
model = YOLO(model_path)
# 模型预测
for i in range(100):# 开始计时startTime = datetime.datetime.now()# 模型预测# img = cv2.imread(predict_ImgPath)results = model.predict(source=predict_ImgPath,imgsz=imgsz) # save plotted images# 结束计时endTime = datetime.datetime.now()# 计算耗时durTime = '模型推理时间:%dms' % ((endTime - startTime).seconds * 1000 + (endTime - startTime).microseconds / 1000)# 打印耗时print(durTime)
更多推荐
Yolov8之部署测试
发布评论