zh/modes/predict/ #7982
Replies: 19 comments 29 replies
-
I finished my training.when I detect my images,how can i chang the box color? |
Beta Was this translation helpful? Give feedback.
-
if iuse model.predict(stream=True),how to stop predict |
Beta Was this translation helpful? Give feedback.
-
hello,I want to make my predictions output format like this,
}] |
Beta Was this translation helpful? Give feedback.
-
I trained a data label of my own, person-with-bag, how do I count all the number of that label in a video? code like this: model = YOLO("D:\ultralytics-main\person-with-bag-best.pt")
|
Beta Was this translation helpful? Give feedback.
-
I try the code you give me ,but when I run the code ,there is a error , the information :Traceback (most recent call last):
File "D:\ultralytics-main\Task\PersonCount.py", line 55, in <module>
if det.cls == model.names.index('person'):
AttributeError: 'dict' object has no attribute 'index'
908637049
***@***.***
…------------------ 原始邮件 ------------------
发件人: "ultralytics/ultralytics" ***@***.***>;
发送时间: 2024年3月19日(星期二) 晚上6:05
***@***.***>;
***@***.******@***.***>;
主题: Re: [ultralytics/ultralytics] zh/modes/predict/ (Discussion #7982)
@nwpu-caikun hello! 😊 To count all instances of your custom label "person-with-bag" in a video, you need to filter your results by the specific class and sum them up over all frames. Here's how you can modify your code to achieve that:
import cv2 from ultralytics import YOLO # Load your custom trained model model = YOLO("D:\\ultralytics-main\\person-with-bag-best.pt") cap = cv2.VideoCapture("D:\\ultralytics-main\\Resource\\b1-0208-0809.mp4") # Initialize the counter label_count = 0 while cap.isOpened(): success, frame = cap.read() if not success: break # Run inference results = model(frame) annotated_frame = results[0].plot() # Filter detections by your custom label and count for det in results[0].boxes: if det.cls == model.names.index('person-with-bag'): label_count += 1 video_writer.write(annotated_frame) print(f"Total 'person-with-bag' count: {label_count}")
Please make sure to replace 'person-with-bag' with the exact name of your class in the model's names attribute. This code assumes that you have a video writer setup (video_writer.write(annotated_frame)) to output the processed video. Let me know if this helps or if you have any further questions! 🚀
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I used your official code when counting the number of person in a one-hour video. In the final result I got the in_count number 751 and out_count number 1334. But the maximum tag number of person in the video is 5547 , does the maximum tag number have anything to do with the total number of in_count plus the out_count number ? pic are blow :
the main code is here:
while cap.isOpened():
success, im0 = cap.read()
if not success:
print("Video frame is empty or video processing has been successfully completed.")
break
tracks = model.track(im0, persist=True, show=False,classes= 0)
im0 = counter.start_counting(im0, tracks)
print("in_count:{}".format(counter.in_counts))
print("out_count:{}".format(counter.out_counts))
video_writer.write(im0)
908637049
***@***.***
…------------------ 原始邮件 ------------------
发件人: "ultralytics/ultralytics" ***@***.***>;
发送时间: 2024年3月19日(星期二) 晚上6:05
***@***.***>;
***@***.******@***.***>;
主题: Re: [ultralytics/ultralytics] zh/modes/predict/ (Discussion #7982)
@nwpu-caikun hello! 😊 To count all instances of your custom label "person-with-bag" in a video, you need to filter your results by the specific class and sum them up over all frames. Here's how you can modify your code to achieve that:
import cv2 from ultralytics import YOLO # Load your custom trained model model = YOLO("D:\\ultralytics-main\\person-with-bag-best.pt") cap = cv2.VideoCapture("D:\\ultralytics-main\\Resource\\b1-0208-0809.mp4") # Initialize the counter label_count = 0 while cap.isOpened(): success, frame = cap.read() if not success: break # Run inference results = model(frame) annotated_frame = results[0].plot() # Filter detections by your custom label and count for det in results[0].boxes: if det.cls == model.names.index('person-with-bag'): label_count += 1 video_writer.write(annotated_frame) print(f"Total 'person-with-bag' count: {label_count}")
Please make sure to replace 'person-with-bag' with the exact name of your class in the model's names attribute. This code assumes that you have a video writer setup (video_writer.write(annotated_frame)) to output the processed video. Let me know if this helps or if you have any further questions! 🚀
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
hello,when I predict a 2MB mp4 video,the model returns me a 50MB avi video, how can I get a smaller video and how can I specify the return type like .mp4? thx |
Beta Was this translation helpful? Give feedback.
-
I am using the model to finish a image classification task, how can i get the predictive result and put it in a list? |
Beta Was this translation helpful? Give feedback.
-
Can you give some demo code for deployment? For example, |
Beta Was this translation helpful? Give feedback.
-
how can i change the save_dir and the save_crop_dir? |
Beta Was this translation helpful? Give feedback.
-
How to add a segmentation head for lane detection based on the target detection model. |
Beta Was this translation helpful? Give feedback.
-
How to choose the information to save in txt |
Beta Was this translation helpful? Give feedback.
-
Hello,Where does predictor return the results? |
Beta Was this translation helpful? Give feedback.
-
Hello,How to customize the return result of the model? |
Beta Was this translation helpful? Give feedback.
-
How to display the normal video playback speed in real time when detecting video files in yolov8? |
Beta Was this translation helpful? Give feedback.
-
when i use the "stream=True",the code return an error "FutureWarning: You are using 进程已结束,退出代码为 0" what can i do to deal with this bug? |
Beta Was this translation helpful? Give feedback.
-
How to change different batch size when I predict video with yolov8? |
Beta Was this translation helpful? Give feedback.
-
你好,我在以安装最新版yolo和torch11.8使用时发现预测十分卡顿,实时延迟可能有3到5秒,代码如下: -- coding: utf-8 --import torch import cv2 cap = cv2.VideoCapture(1) while cap.isOpened():
请问如何解决,谢谢 |
Beta Was this translation helpful? Give feedback.
-
can I save my predict result as .xml files? |
Beta Was this translation helpful? Give feedback.
-
zh/modes/predict/
了解如何在各种任务中使用YOLOv8 预测模式。了解不同的推理源,如图像、视频和数据格式。
https://docs.ultralytics.com/zh/modes/predict/
Beta Was this translation helpful? Give feedback.
All reactions