Skip to content

Commit

Permalink
Docs Ruff codeblocks reformat and fix (ultralytics#12847)
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn Jocher <[email protected]>
  • Loading branch information
glenn-jocher authored May 19, 2024
1 parent be5cf7a commit 6803113
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 178 deletions.
6 changes: 3 additions & 3 deletions docs/en/datasets/pose/tiger-pose.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ The example showcases the variety and complexity of the images in the Tiger-Pose
from ultralytics import YOLO

# Load a model
model = YOLO('path/to/best.pt') # load a tiger-pose trained model
model = YOLO("path/to/best.pt") # load a tiger-pose trained model

# Run inference
results = model.predict(source="https://www.youtube.com/watch?v=MIBAT6BGE6U&pp=ygUYdGlnZXIgd2Fsa2luZyByZWZlcmVuY2Ug" show=True)
results = model.predict(source="https://youtu.be/MIBAT6BGE6U", show=True)
```

=== "CLI"

```bash
# Run inference using a tiger-pose trained model
yolo task=pose mode=predict source="https://www.youtube.com/watch?v=MIBAT6BGE6U&pp=ygUYdGlnZXIgd2Fsa2luZyByZWZlcmVuY2Ug" show=True model="path/to/best.pt"
yolo task=pose mode=predict source="https://youtu.be/MIBAT6BGE6U" show=True model="path/to/best.pt"
```

## Citations and Acknowledgments
Expand Down
2 changes: 1 addition & 1 deletion docs/en/guides/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 8 additions & 15 deletions docs/en/guides/isolating-segmentation-objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand Down
17 changes: 8 additions & 9 deletions docs/en/guides/view-results-in-terminal.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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")
Expand All @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions docs/en/integrations/tensorboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ TensorBoard is conveniently pre-installed with YOLOv8, eliminating the need for

For detailed instructions and best practices related to the installation process, be sure to check our [YOLOv8 Installation guide](../quickstart.md). While installing the required packages for YOLOv8, if you encounter any difficulties, consult our [Common Issues guide](../guides/yolo-common-issues.md) for solutions and tips.

## Configuring TensorBoard for Google Collab
## Configuring TensorBoard for Google Colab

When using Google Colab, it's important to set up TensorBoard before starting your training code:

!!! Example "Configure TensorBoard for Google Collab"
!!! Example "Configure TensorBoard for Google Colab"

=== "Python"

```python
```ipython
%load_ext tensorboard
%tensorboard --logdir path/to/runs
```
Expand Down
43 changes: 11 additions & 32 deletions docs/en/integrations/tensorrt.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,16 @@ Experimentation by NVIDIA led them to recommend using at least 500 calibration i
model = YOLO("yolov8n.pt")
model.export(
format="engine",
dynamic=True, #(1)!
batch=8, #(2)!
workspace=4, #(3)!
dynamic=True, # (1)!
batch=8, # (2)!
workspace=4, # (3)!
int8=True,
data="coco.yaml", #(4)!
data="coco.yaml", # (4)!
)

# Load the exported TensorRT INT8 model
model = YOLO("yolov8n.engine", task="detect")

# Run inference
result = model.predict("https://ultralytics.com/images/bus.jpg")
```
Expand Down Expand Up @@ -385,36 +386,14 @@ Expand sections below for information on how these models were exported and test
model = YOLO("yolov8n.pt")

# TensorRT FP32
out = model.export(
format="engine",
imgsz:640,
dynamic:True,
verbose:False,
batch:8,
workspace:2
)

out = model.export(format="engine", imgsz=640, dynamic=True, verbose=False, batch=8, workspace=2)

# TensorRT FP16
out = model.export(format="engine", imgsz=640, dynamic=True, verbose=False, batch=8, workspace=2, half=True)

# TensorRT INT8 with calibration `data` (i.e. COCO, ImageNet, or DOTAv1 for appropriate model task)
out = model.export(
format="engine",
imgsz:640,
dynamic:True,
verbose:False,
batch:8,
workspace:2,
half=True
)

# TensorRT INT8
out = model.export(
format="engine",
imgsz:640,
dynamic:True,
verbose:False,
batch:8,
workspace:2,
int8=True,
data:"data.yaml" # COCO, ImageNet, or DOTAv1 for appropriate model task
format="engine", imgsz=640, dynamic=True, verbose=False, batch=8, workspace=2, int8=True, data="coco8.yaml"
)
```

Expand Down
42 changes: 25 additions & 17 deletions docs/en/usage/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,31 @@ Val mode is used for validating a YOLOv8 model after it has been trained. In thi
=== "Val after training"

```python
from ultralytics import YOLO
from ultralytics import YOLO

# Load a YOLOv8 model
model = YOLO("yolov8n.yaml")

model = YOLO('yolov8n.yaml')
model.train(data='coco8.yaml', epochs=5)
model.val() # It'll automatically evaluate the data you trained.
# Train the model
model.train(data="coco8.yaml", epochs=5)

# Validate on training data
model.val()
```

=== "Val independently"
=== "Val on another dataset"

```python
from ultralytics import YOLO
from ultralytics import YOLO

model = YOLO("model.pt")
# It'll use the data YAML file in model.pt if you don't set data.
model.val()
# or you can set the data you want to val
model.val(data='coco8.yaml')
# Load a YOLOv8 model
model = YOLO("yolov8n.yaml")

# Train the model
model.train(data="coco8.yaml", epochs=5)

# Validate on separate data
model.val(data="path/to/separate/data.yaml")
```

[Val Examples](../modes/val.md){ .md-button }
Expand Down Expand Up @@ -188,20 +196,20 @@ Export mode is used for exporting a YOLOv8 model to a format that can be used fo

Export an official YOLOv8n model to ONNX with dynamic batch-size and image-size.
```python
from ultralytics import YOLO
from ultralytics import YOLO

model = YOLO('yolov8n.pt')
model.export(format='onnx', dynamic=True)
model = YOLO("yolov8n.pt")
model.export(format="onnx", dynamic=True)
```

=== "Export to TensorRT"

Export an official YOLOv8n model to TensorRT on `device=0` for acceleration on CUDA devices.
```python
from ultralytics import YOLO
from ultralytics import YOLO

model = YOLO('yolov8n.pt')
model.export(format='onnx', device=0)
model = YOLO("yolov8n.pt")
model.export(format="onnx", device=0)
```

[Export Examples](../modes/export.md){ .md-button }
Expand Down
Loading

0 comments on commit 6803113

Please sign in to comment.