You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/modes/predict.md
+46-1Lines changed: 46 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -152,7 +152,8 @@ operations are cached, meaning they're only calculated once per object, and thos
152
152
```python
153
153
results = model(inputs)
154
154
masks = results[0].masks # Masks object
155
-
masks.segments # bounding coordinates of masks, List[segment] * N
155
+
masks.xy # x, y segments (pixels), List[segment] * N
156
+
masks.xyn # x, y segments (normalized), List[segment] * N
156
157
masks.data # raw masks tensor, (N, H, W) or masks.masks
157
158
```
158
159
@@ -185,3 +186,47 @@ masks, classification logits, etc.) found in the results object
185
186
-`show_conf (bool)`: Show confidence
186
187
-`line_width (Float)`: The line width of boxes. Automatically scaled to img size if not provided
187
188
-`font_size (Float)`: The font size of . Automatically scaled to img size if not provided
189
+
190
+
## Streaming Source `for`-loop
191
+
192
+
Here's a Python script using OpenCV (cv2) and YOLOv8 to run inference on video frames. This script assumes you have already installed the necessary packages (opencv-python and ultralytics).
193
+
194
+
!!! example "Streaming for-loop"
195
+
196
+
```python
197
+
import cv2
198
+
from ultralytics import YOLO
199
+
200
+
# Load the YOLOv8 model
201
+
model = YOLO('yolov8n.pt')
202
+
203
+
# Open the video file
204
+
video_path = "path/to/your/video/file.mp4"
205
+
cap = cv2.VideoCapture(video_path)
206
+
207
+
# Loop through the video frames
208
+
while cap.isOpened():
209
+
# Read a frame from the video
210
+
success, frame = cap.read()
211
+
212
+
if success:
213
+
# Run YOLOv8 inference on the frame
214
+
results = model(frame)
215
+
216
+
# Visualize the results on the frame
217
+
annotated_frame = results[0].plot()
218
+
219
+
# Display the annotated frame
220
+
cv2.imshow("YOLOv8 Inference", annotated_frame)
221
+
222
+
# Break the loop if 'q' is pressed
223
+
if cv2.waitKey(1) & 0xFF == ord("q"):
224
+
break
225
+
else:
226
+
# Break the loop if the end of the video is reached
227
+
break
228
+
229
+
# Release the video capture object and close the display window
Here are all supported callbacks. See callbacks [source code](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/yolo/utils/callbacks/base.py) for additional details.
Training settings for YOLO models refer to the various hyperparameters and configurations used to train the model on a
58
-
dataset. These settings can affect the model's performance, speed, and accuracy. Some common YOLO training settings
59
-
include the batch size, learning rate, momentum, and weight decay. Other factors that may affect the training process
60
-
include the choice of optimizer, the choice of loss function, and the size and composition of the training dataset. It
61
-
is important to carefully tune and experiment with these settings to achieve the best possible performance for a given
62
-
task.
73
+
The training settings for YOLO models encompass various hyperparameters and configurations used during the training process. These settings influence the model's performance, speed, and accuracy. Key training settings include batch size, learning rate, momentum, and weight decay. Additionally, the choice of optimizer, loss function, and training dataset composition can impact the training process. Careful tuning and experimentation with these settings are crucial for optimizing performance.
Prediction settings for YOLO models refer to the various hyperparameters and configurations used to make predictions
113
-
with the model on new data. These settings can affect the model's performance, speed, and accuracy. Some common YOLO
114
-
prediction settings include the confidence threshold, non-maximum suppression (NMS) threshold, and the number of classes
115
-
to consider. Other factors that may affect the prediction process include the size and format of the input data, the
116
-
presence of additional features such as masks or multiple labels per box, and the specific task the model is being used
117
-
for. It is important to carefully tune and experiment with these settings to achieve the best possible performance for a
118
-
given task.
123
+
## Predict
124
+
125
+
The prediction settings for YOLO models encompass a range of hyperparameters and configurations that influence the model's performance, speed, and accuracy during inference on new data. Careful tuning and experimentation with these settings are essential to achieve optimal performance for a specific task. Key settings include the confidence threshold, Non-Maximum Suppression (NMS) threshold, and the number of classes considered. Additional factors affecting the prediction process are input data size and format, the presence of supplementary features such as masks or multiple labels per box, and the particular task the model is employed for.
Validation settings for YOLO models refer to the various hyperparameters and configurations used to
147
-
evaluate the model's performance on a validation dataset. These settings can affect the model's performance, speed, and
148
-
accuracy. Some common YOLO validation settings include the batch size, the frequency with which validation is performed
149
-
during training, and the metrics used to evaluate the model's performance. Other factors that may affect the validation
150
-
process include the size and composition of the validation dataset and the specific task the model is being used for. It
151
-
is important to carefully tune and experiment with these settings to ensure that the model is performing well on the
152
-
validation dataset and to detect and prevent overfitting.
155
+
The val (validation) settings for YOLO models involve various hyperparameters and configurations used to evaluate the model's performance on a validation dataset. These settings influence the model's performance, speed, and accuracy. Common YOLO validation settings include batch size, validation frequency during training, and performance evaluation metrics. Other factors affecting the validation process include the validation dataset's size and composition, as well as the specific task the model is employed for. Careful tuning and experimentation with these settings are crucial to ensure optimal performance on the validation dataset and detect and prevent overfitting.
Export settings for YOLO models refer to the various configurations and options used to save or
171
-
export the model for use in other environments or platforms. These settings can affect the model's performance, size,
172
-
and compatibility with different systems. Some common YOLO export settings include the format of the exported model
173
-
file (e.g. ONNX, TensorFlow SavedModel), the device on which the model will be run (e.g. CPU, GPU), and the presence of
174
-
additional features such as masks or multiple labels per box. Other factors that may affect the export process include
175
-
the specific task the model is being used for and the requirements or constraints of the target environment or platform.
176
-
It is important to carefully consider and configure these settings to ensure that the exported model is optimized for
177
-
the intended use case and can be used effectively in the target environment.
173
+
## Export
174
+
175
+
Export settings for YOLO models encompass configurations and options related to saving or exporting the model for use in different environments or platforms. These settings can impact the model's performance, size, and compatibility with various systems. Key export settings include the exported model file format (e.g., ONNX, TensorFlow SavedModel), the target device (e.g., CPU, GPU), and additional features such as masks or multiple labels per box. The export process may also be affected by the model's specific task and the requirements or constraints of the destination environment or platform. It is crucial to thoughtfully configure these settings to ensure the exported model is optimized for the intended use case and functions effectively in the target environment.
0 commit comments