Yolo nas prediction model: unexpected keyword argument 'save'

404 Views Asked by At

i am learning in Yolo nas model for object detection, so in Yolov8 i was able to save the predictions coordinates as txt but using this

yolov8.predict(url, save = True, conf=0.70, save_txt = True)

but in yolo Nas i am not able to, i am getting this error

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'

so i wanna ask how to solve this problem and if there is a place to get familier with all Yolo nas functions and its parameters

1

There are 1 best solutions below

1
On

Check this out for real-time inferanceing with 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

Check this out. Yolo-NAS (State of Art object detection model) with OpenCV for real-time predictions. Prediction results are mind-blowing with higher inference speed and prediction accuracy compared to YoloV8 models.

cv2.VideoCapture(0)

For real-time predictions with Webcam

Check this link for more details text