Docs Ruff codeblocks reformat and fix (#12847)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
parent
be5cf7a033
commit
68031133fd
9 changed files with 167 additions and 178 deletions
|
|
@ -35,7 +35,7 @@ Here's a compilation of in-depth guides to help you master different aspects of
|
|||
- [Conda Quickstart](conda-quickstart.md) 🚀 NEW: Step-by-step guide to setting up a [Conda](https://anaconda.org/conda-forge/ultralytics) environment for Ultralytics. Learn how to install and start using the Ultralytics package efficiently with Conda.
|
||||
- [Docker Quickstart](docker-quickstart.md) 🚀 NEW: Complete guide to setting up and using Ultralytics YOLO models with [Docker](https://hub.docker.com/r/ultralytics/ultralytics). Learn how to install Docker, manage GPU support, and run YOLO models in isolated containers for consistent development and deployment.
|
||||
- [Raspberry Pi](raspberry-pi.md) 🚀 NEW: Quickstart tutorial to run YOLO models to the latest Raspberry Pi hardware.
|
||||
- [Nvidia-Jetson](nvidia-jetson.md)🚀 NEW: Quickstart guide for deploying YOLO models on Nvidia Jetson devices.
|
||||
- [NVIDIA-Jetson](nvidia-jetson.md)🚀 NEW: Quickstart guide for deploying YOLO models on NVIDIA Jetson devices.
|
||||
- [Triton Inference Server Integration](triton-inference-server.md) 🚀 NEW: Dive into the integration of Ultralytics YOLOv8 with NVIDIA's Triton Inference Server for scalable and efficient deep learning inference deployments.
|
||||
- [YOLO Thread-Safe Inference](yolo-thread-safe-inference.md) 🚀 NEW: Guidelines for performing inference with YOLO models in a thread-safe manner. Learn the importance of thread safety and best practices to prevent race conditions and ensure consistent predictions.
|
||||
- [Isolating Segmentation Objects](isolating-segmentation-objects.md) 🚀 NEW: Step-by-step recipe and explanation on how to extract and/or isolate objects from images using Ultralytics Segmentation.
|
||||
|
|
|
|||
|
|
@ -63,13 +63,12 @@ After performing the [Segment Task](../tasks/segment.md), it's sometimes desirab
|
|||
# (2) Iterate detection results (helpful for multiple images)
|
||||
for r in res:
|
||||
img = np.copy(r.orig_img)
|
||||
img_name = Path(r.path).stem # source image base-name
|
||||
img_name = Path(r.path).stem # source image base-name
|
||||
|
||||
# Iterate each object contour (multiple detections)
|
||||
for ci,c in enumerate(r):
|
||||
for ci, c in enumerate(r):
|
||||
# (1) Get detection class name
|
||||
label = c.names[c.boxes.cls.tolist().pop()]
|
||||
|
||||
```
|
||||
|
||||
1. To learn more about working with detection results, see [Boxes Section for Predict Mode](../modes/predict.md#boxes).
|
||||
|
|
@ -98,12 +97,7 @@ After performing the [Segment Task](../tasks/segment.md), it's sometimes desirab
|
|||
|
||||
|
||||
# Draw contour onto mask
|
||||
_ = cv2.drawContours(b_mask,
|
||||
[contour],
|
||||
-1,
|
||||
(255, 255, 255),
|
||||
cv2.FILLED)
|
||||
|
||||
_ = cv2.drawContours(b_mask, [contour], -1, (255, 255, 255), cv2.FILLED)
|
||||
```
|
||||
|
||||
1. For more info on `c.masks.xy` see [Masks Section from Predict Mode](../modes/predict.md#masks).
|
||||
|
|
@ -280,16 +274,16 @@ import cv2
|
|||
import numpy as np
|
||||
from ultralytics import YOLO
|
||||
|
||||
m = YOLO('yolov8n-seg.pt')#(4)!
|
||||
res = m.predict()#(3)!
|
||||
m = YOLO("yolov8n-seg.pt") # (4)!
|
||||
res = m.predict() # (3)!
|
||||
|
||||
# iterate detection results (5)
|
||||
# Iterate detection results (5)
|
||||
for r in res:
|
||||
img = np.copy(r.orig_img)
|
||||
img_name = Path(r.path).stem
|
||||
|
||||
# iterate each object contour (6)
|
||||
for ci,c in enumerate(r):
|
||||
# Iterate each object contour (6)
|
||||
for ci, c in enumerate(r):
|
||||
label = c.names[c.boxes.cls.tolist().pop()]
|
||||
|
||||
b_mask = np.zeros(img.shape[:2], np.uint8)
|
||||
|
|
@ -312,7 +306,6 @@ for r in res:
|
|||
iso_crop = isolated[y1:y2, x1:x2]
|
||||
|
||||
# TODO your actions go here (2)
|
||||
|
||||
```
|
||||
|
||||
1. The line populating `contour` is combined into a single line here, where it was split to multiple above.
|
||||
|
|
|
|||
|
|
@ -61,9 +61,9 @@ The VSCode compatible protocols for viewing images using the integrated terminal
|
|||
|
||||
# Run inference on an image
|
||||
results = model.predict(source="ultralytics/assets/bus.jpg")
|
||||
|
||||
|
||||
# Plot inference results
|
||||
plot = results[0].plot() #(1)!
|
||||
plot = results[0].plot() # (1)!
|
||||
```
|
||||
|
||||
1. See [plot method parameters](../modes/predict.md#plot-method-parameters) to see possible arguments to use.
|
||||
|
|
@ -73,9 +73,9 @@ The VSCode compatible protocols for viewing images using the integrated terminal
|
|||
```{ .py .annotate }
|
||||
# Results image as bytes
|
||||
im_bytes = cv.imencode(
|
||||
".png", #(1)!
|
||||
".png", # (1)!
|
||||
plot,
|
||||
)[1].tobytes() #(2)!
|
||||
)[1].tobytes() # (2)!
|
||||
|
||||
# Image bytes as a file-like object
|
||||
mem_file = io.BytesIO(im_bytes)
|
||||
|
|
@ -110,9 +110,8 @@ The VSCode compatible protocols for viewing images using the integrated terminal
|
|||
import io
|
||||
|
||||
import cv2 as cv
|
||||
|
||||
from ultralytics import YOLO
|
||||
from sixel import SixelWriter
|
||||
from ultralytics import YOLO
|
||||
|
||||
# Load a model
|
||||
model = YOLO("yolov8n.pt")
|
||||
|
|
@ -121,13 +120,13 @@ model = YOLO("yolov8n.pt")
|
|||
results = model.predict(source="ultralytics/assets/bus.jpg")
|
||||
|
||||
# Plot inference results
|
||||
plot = results[0].plot() #(3)!
|
||||
plot = results[0].plot() # (3)!
|
||||
|
||||
# Results image as bytes
|
||||
im_bytes = cv.imencode(
|
||||
".png", #(1)!
|
||||
".png", # (1)!
|
||||
plot,
|
||||
)[1].tobytes() #(2)!
|
||||
)[1].tobytes() # (2)!
|
||||
|
||||
mem_file = io.BytesIO(im_bytes)
|
||||
w = SixelWriter()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue