我正在学习用于对象检测的 Yolo nas 模型,因此在 Yolov8 中我能够将预测坐标保存为 txt 但使用这个
yolov8.predict(url, save = True, conf=0.70, save_txt = True)
但在 yolo Nas 中我无法做到,我收到此错误
TypeError Traceback (most recent call last)
<ipython-input-24-788df24f8115> in <cell line: 2>()
1 url = "/WhatsApp Image 2023-09-16 at 16.22.49.jpeg"
----> 2 yolo_nas_l.predict(url, save = True, conf=0.70, save_txt = True).show()
3
TypeError: CustomizableDetector.predict() got an unexpected keyword argument 'save'
所以我想问一下如何解决这个问题 如果有地方可以熟悉所有 Yolo nas 函数及其参数
查看使用 Yolo-NAS 进行实时推理
import cv2
import time
import torch
from ultralytics.yolo.utils.plotting import Annotator
yolo_nas_l = models.get("yolo_nas_m", pretrained_weights="coco")
cap = cv2.VideoCapture(input_video_path)
width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
fps_v = cap.get(cv2.CAP_PROP_FPS)
video_writer = cv2.VideoWriter(
"Save.mp4",cv2.VideoWriter_fourcc(*"mp4v"),fps_v, (int(width), int(height)),)
device = 'cuda' if torch.cuda.is_available() else "cpu"
model=yolo_nas_l.to(device)
prevTime=0
while True:
_, frame = cap.read()
if not _:
break
annotator = Annotator(frame)
images_predictions = model.predict(frame)
#image_prediction = next(iter(images_predictions))
for image_prediction in images_predictions:
image = image_prediction.image
labels = image_prediction.prediction.labels
confidence = image_prediction.prediction.confidence
bboxes = image_prediction.prediction.bboxes_xyxy
for i in range(len(labels)):
conf=str(round(confidence[i],2))
lab=labels[i]
annotator.box_label(bboxes[i],f"{lab} {conf}")
currTime = time.time()
fps = 1 / (currTime - prevTime)
prevTime = currTime
cv2.line(frame, (20, 25), (127, 25), [85, 45, 255], 30)
cv2.putText(frame, f'FPS: {int(fps)}', (11, 35), 0, 1, [225, 255, 255], thickness=2, lineType=cv2.LINE_AA)
video_writer.write(frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
看看这个。 Yolo-NAS(最先进的对象检测模型)与 OpenCV 进行实时预测。与 YoloV8 模型相比,预测结果令人惊叹,具有更高的推理速度和预测精度。
cv2.VideoCapture(0)
使用网络摄像头进行实时预测
查看此链接了解更多详情text