Reformat Markdown code blocks (#12795)

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
This commit is contained in:
Glenn Jocher 2024-05-18 18:58:06 +02:00 committed by GitHub
parent 2af71d15a6
commit fceea033ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
128 changed files with 1067 additions and 1018 deletions

View file

@ -117,21 +117,22 @@ After creating the AWS CloudFormation Stack, the next step is to deploy YOLOv8.
```python
import json
def output_fn(prediction_output, content_type):
"""Formats model outputs as JSON string according to content_type, extracting attributes like boxes, masks, keypoints."""
print("Executing output_fn from inference.py ...")
infer = {}
for result in prediction_output:
if result.boxes is not None:
infer['boxes'] = result.boxes.numpy().data.tolist()
infer["boxes"] = result.boxes.numpy().data.tolist()
if result.masks is not None:
infer['masks'] = result.masks.numpy().data.tolist()
infer["masks"] = result.masks.numpy().data.tolist()
if result.keypoints is not None:
infer['keypoints'] = result.keypoints.numpy().data.tolist()
infer["keypoints"] = result.keypoints.numpy().data.tolist()
if result.obb is not None:
infer['obb'] = result.obb.numpy().data.tolist()
infer["obb"] = result.obb.numpy().data.tolist()
if result.probs is not None:
infer['probs'] = result.probs.numpy().data.tolist()
infer["probs"] = result.probs.numpy().data.tolist()
return json.dumps(infer)
```

View file

@ -67,17 +67,14 @@ Before diving into the usage instructions, be sure to check out the range of [YO
from ultralytics import YOLO
# Step 1: Creating a ClearML Task
task = Task.init(
project_name="my_project",
task_name="my_yolov8_task"
)
task = Task.init(project_name="my_project", task_name="my_yolov8_task")
# Step 2: Selecting the YOLOv8 Model
model_variant = "yolov8n"
task.set_parameter("model_variant", model_variant)
# Step 3: Loading the YOLOv8 Model
model = YOLO(f'{model_variant}.pt')
model = YOLO(f"{model_variant}.pt")
# Step 4: Setting Up Training Arguments
args = dict(data="coco8.yaml", epochs=16)

View file

@ -74,12 +74,12 @@ Before diving into the usage instructions, be sure to check out the range of [YO
# train the model
results = model.train(
data="coco8.yaml",
project="comet-example-yolov8-coco128",
batch=32,
save_period=1,
save_json=True,
epochs=3
data="coco8.yaml",
project="comet-example-yolov8-coco128",
batch=32,
save_period=1,
save_json=True,
epochs=3,
)
```
@ -144,7 +144,7 @@ Comet ML allows you to specify how often batches of image predictions are logged
```python
import os
os.environ['COMET_EVAL_BATCH_LOGGING_INTERVAL'] = "4"
os.environ["COMET_EVAL_BATCH_LOGGING_INTERVAL"] = "4"
```
### Disabling Confusion Matrix Logging

View file

@ -83,16 +83,16 @@ Before diving into the usage instructions, be sure to check out the range of [YO
from ultralytics import YOLO
# Load the YOLOv8 model
model = YOLO('yolov8n.pt')
model = YOLO("yolov8n.pt")
# Export the model to CoreML format
model.export(format='coreml') # creates 'yolov8n.mlpackage'
model.export(format="coreml") # creates 'yolov8n.mlpackage'
# Load the exported CoreML model
coreml_model = YOLO('yolov8n.mlpackage')
coreml_model = YOLO("yolov8n.mlpackage")
# Run inference
results = coreml_model('https://ultralytics.com/images/bus.jpg')
results = coreml_model("https://ultralytics.com/images/bus.jpg")
```
=== "CLI"

View file

@ -149,7 +149,7 @@ If you are using a Jupyter Notebook and you want to display the generated DVC pl
from IPython.display import HTML
# Display the DVC plots as HTML
HTML(filename='./dvc_plots/index.html')
HTML(filename="./dvc_plots/index.html")
```
This code will render the HTML file containing the DVC plots directly in your Jupyter Notebook, providing an easy and convenient way to analyze the visualized experiment data.

View file

@ -73,16 +73,16 @@ Before diving into the usage instructions, it's important to note that while all
from ultralytics import YOLO
# Load the YOLOv8 model
model = YOLO('yolov8n.pt')
model = YOLO("yolov8n.pt")
# Export the model to TFLite Edge TPU format
model.export(format='edgetpu') # creates 'yolov8n_full_integer_quant_edgetpu.tflite
model.export(format="edgetpu") # creates 'yolov8n_full_integer_quant_edgetpu.tflite
# Load the exported TFLite Edge TPU model
edgetpu_model = YOLO('yolov8n_full_integer_quant_edgetpu.tflite')
edgetpu_model = YOLO("yolov8n_full_integer_quant_edgetpu.tflite")
# Run inference
results = edgetpu_model('https://ultralytics.com/images/bus.jpg')
results = edgetpu_model("https://ultralytics.com/images/bus.jpg")
```
=== "CLI"

View file

@ -44,9 +44,8 @@ pip install gradio
This section provides the Python code used to create the Gradio interface with the Ultralytics YOLOv8 model. Supports classification tasks, detection tasks, segmentation tasks, and key point tasks.
```python
import PIL.Image as Image
import gradio as gr
import PIL.Image as Image
from ultralytics import ASSETS, YOLO
model = YOLO("yolov8n.pt")
@ -75,7 +74,7 @@ iface = gr.Interface(
inputs=[
gr.Image(type="pil", label="Upload Image"),
gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold")
gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
],
outputs=gr.Image(type="pil", label="Result"),
title="Ultralytics Gradio",
@ -83,10 +82,10 @@ iface = gr.Interface(
examples=[
[ASSETS / "bus.jpg", 0.25, 0.45],
[ASSETS / "zidane.jpg", 0.25, 0.45],
]
],
)
if __name__ == '__main__':
if __name__ == "__main__":
iface.launch()
```

View file

@ -42,7 +42,7 @@ Make sure that MLflow logging is enabled in Ultralytics settings. Usually, this
from ultralytics import settings
# Update a setting
settings.update({'mlflow': True})
settings.update({"mlflow": True})
# Reset settings to default values
settings.reset()

View file

@ -73,18 +73,18 @@ Before diving into the usage instructions, it's important to note that while all
```python
from ultralytics import YOLO
# Load the YOLOv8 model
model = YOLO('yolov8n.pt')
model = YOLO("yolov8n.pt")
# Export the model to NCNN format
model.export(format='ncnn') # creates '/yolov8n_ncnn_model'
model.export(format="ncnn") # creates '/yolov8n_ncnn_model'
# Load the exported NCNN model
ncnn_model = YOLO('./yolov8n_ncnn_model')
ncnn_model = YOLO("./yolov8n_ncnn_model")
# Run inference
results = ncnn_model('https://ultralytics.com/images/bus.jpg')
results = ncnn_model("https://ultralytics.com/images/bus.jpg")
```
=== "CLI"

View file

@ -109,10 +109,7 @@ With your YOLOv8 model in ONNX format, you can deploy and run inferences using D
model_path = "path/to/yolov8n.onnx"
# Set up the DeepSparse Pipeline
yolo_pipeline = Pipeline.create(
task="yolov8",
model_path=model_path
)
yolo_pipeline = Pipeline.create(task="yolov8", model_path=model_path)
# Run the model on your images
images = ["path/to/image.jpg"]

View file

@ -91,16 +91,16 @@ Before diving into the usage instructions, be sure to check out the range of [YO
from ultralytics import YOLO
# Load the YOLOv8 model
model = YOLO('yolov8n.pt')
model = YOLO("yolov8n.pt")
# Export the model to ONNX format
model.export(format='onnx') # creates 'yolov8n.onnx'
model.export(format="onnx") # creates 'yolov8n.onnx'
# Load the exported ONNX model
onnx_model = YOLO('yolov8n.onnx')
onnx_model = YOLO("yolov8n.onnx")
# Run inference
results = onnx_model('https://ultralytics.com/images/bus.jpg')
results = onnx_model("https://ultralytics.com/images/bus.jpg")
```
=== "CLI"

View file

@ -35,16 +35,16 @@ Export a YOLOv8n model to OpenVINO format and run inference with the exported mo
from ultralytics import YOLO
# Load a YOLOv8n PyTorch model
model = YOLO('yolov8n.pt')
model = YOLO("yolov8n.pt")
# Export the model
model.export(format='openvino') # creates 'yolov8n_openvino_model/'
model.export(format="openvino") # creates 'yolov8n_openvino_model/'
# Load the exported OpenVINO model
ov_model = YOLO('yolov8n_openvino_model/')
ov_model = YOLO("yolov8n_openvino_model/")
# Run inference
results = ov_model('https://ultralytics.com/images/bus.jpg')
results = ov_model("https://ultralytics.com/images/bus.jpg")
```
=== "CLI"
@ -259,10 +259,10 @@ To reproduce the Ultralytics benchmarks above on all export [formats](../modes/e
from ultralytics import YOLO
# Load a YOLOv8n PyTorch model
model = YOLO('yolov8n.pt')
model = YOLO("yolov8n.pt")
# Benchmark YOLOv8n speed and accuracy on the COCO8 dataset for all all export formats
results= model.benchmarks(data='coco8.yaml')
results = model.benchmarks(data="coco8.yaml")
```
=== "CLI"

View file

@ -77,16 +77,16 @@ Before diving into the usage instructions, it's important to note that while all
from ultralytics import YOLO
# Load the YOLOv8 model
model = YOLO('yolov8n.pt')
model = YOLO("yolov8n.pt")
# Export the model to PaddlePaddle format
model.export(format='paddle') # creates '/yolov8n_paddle_model'
model.export(format="paddle") # creates '/yolov8n_paddle_model'
# Load the exported PaddlePaddle model
paddle_model = YOLO('./yolov8n_paddle_model')
paddle_model = YOLO("./yolov8n_paddle_model")
# Run inference
results = paddle_model('https://ultralytics.com/images/bus.jpg')
results = paddle_model("https://ultralytics.com/images/bus.jpg")
```
=== "CLI"

View file

@ -50,10 +50,10 @@ To install the required packages, run:
from ultralytics import YOLO
# Load a YOLOv8n model
model = YOLO('yolov8n.pt')
model = YOLO("yolov8n.pt")
# Start tuning hyperparameters for YOLOv8n training on the COCO8 dataset
result_grid = model.tune(data='coco8.yaml', use_ray=True)
result_grid = model.tune(data="coco8.yaml", use_ray=True)
```
## `tune()` Method Parameters
@ -112,10 +112,12 @@ In this example, we demonstrate how to use a custom search space for hyperparame
model = YOLO("yolov8n.pt")
# Run Ray Tune on the model
result_grid = model.tune(data="coco8.yaml",
space={"lr0": tune.uniform(1e-5, 1e-1)},
epochs=50,
use_ray=True)
result_grid = model.tune(
data="coco8.yaml",
space={"lr0": tune.uniform(1e-5, 1e-1)},
epochs=50,
use_ray=True,
)
```
In the code snippet above, we create a YOLO model with the "yolov8n.pt" pretrained weights. Then, we call the `tune()` method, specifying the dataset configuration with "coco8.yaml". We provide a custom search space for the initial learning rate `lr0` using a dictionary with the key "lr0" and the value `tune.uniform(1e-5, 1e-1)`. Finally, we pass additional training arguments, such as the number of epochs directly to the tune method as `epochs=50`.
@ -164,10 +166,14 @@ You can plot the history of reported metrics for each trial to see how the metri
import matplotlib.pyplot as plt
for result in result_grid:
plt.plot(result.metrics_dataframe["training_iteration"], result.metrics_dataframe["mean_accuracy"], label=f"Trial {i}")
plt.plot(
result.metrics_dataframe["training_iteration"],
result.metrics_dataframe["mean_accuracy"],
label=f"Trial {i}",
)
plt.xlabel('Training Iterations')
plt.ylabel('Mean Accuracy')
plt.xlabel("Training Iterations")
plt.ylabel("Mean Accuracy")
plt.legend()
plt.show()
```

View file

@ -85,16 +85,16 @@ Before diving into the usage instructions, be sure to check out the range of [YO
from ultralytics import YOLO
# Load the YOLOv8 model
model = YOLO('yolov8n.pt')
model = YOLO("yolov8n.pt")
# Export the model to TensorRT format
model.export(format='engine') # creates 'yolov8n.engine'
model.export(format="engine") # creates 'yolov8n.engine'
# Load the exported TensorRT model
tensorrt_model = YOLO('yolov8n.engine')
tensorrt_model = YOLO("yolov8n.engine")
# Run inference
results = tensorrt_model('https://ultralytics.com/images/bus.jpg')
results = tensorrt_model("https://ultralytics.com/images/bus.jpg")
```
=== "CLI"
@ -434,7 +434,7 @@ Expand sections below for information on how these models were exported and test
result = model.predict(
[img] * 8, # batch=8 of the same image
verbose=False,
device="cuda"
device="cuda",
)
```
@ -451,7 +451,7 @@ Expand sections below for information on how these models were exported and test
batch=1,
imgsz=640,
verbose=False,
device="cuda"
device="cuda",
)
```

View file

@ -81,16 +81,16 @@ Before diving into the usage instructions, it's important to note that while all
from ultralytics import YOLO
# Load the YOLOv8 model
model = YOLO('yolov8n.pt')
model = YOLO("yolov8n.pt")
# Export the model to TF GraphDef format
model.export(format='pb') # creates 'yolov8n.pb'
model.export(format="pb") # creates 'yolov8n.pb'
# Load the exported TF GraphDef model
tf_graphdef_model = YOLO('yolov8n.pb')
tf_graphdef_model = YOLO("yolov8n.pb")
# Run inference
results = tf_graphdef_model('https://ultralytics.com/images/bus.jpg')
results = tf_graphdef_model("https://ultralytics.com/images/bus.jpg")
```
=== "CLI"

View file

@ -75,16 +75,16 @@ Before diving into the usage instructions, it's important to note that while all
from ultralytics import YOLO
# Load the YOLOv8 model
model = YOLO('yolov8n.pt')
model = YOLO("yolov8n.pt")
# Export the model to TF SavedModel format
model.export(format='saved_model') # creates '/yolov8n_saved_model'
model.export(format="saved_model") # creates '/yolov8n_saved_model'
# Load the exported TF SavedModel model
tf_savedmodel_model = YOLO('./yolov8n_saved_model')
tf_savedmodel_model = YOLO("./yolov8n_saved_model")
# Run inference
results = tf_savedmodel_model('https://ultralytics.com/images/bus.jpg')
results = tf_savedmodel_model("https://ultralytics.com/images/bus.jpg")
```
=== "CLI"

View file

@ -73,16 +73,16 @@ Before diving into the usage instructions, it's important to note that while all
from ultralytics import YOLO
# Load the YOLOv8 model
model = YOLO('yolov8n.pt')
model = YOLO("yolov8n.pt")
# Export the model to TF.js format
model.export(format='tfjs') # creates '/yolov8n_web_model'
model.export(format="tfjs") # creates '/yolov8n_web_model'
# Load the exported TF.js model
tfjs_model = YOLO('./yolov8n_web_model')
tfjs_model = YOLO("./yolov8n_web_model")
# Run inference
results = tfjs_model('https://ultralytics.com/images/bus.jpg')
results = tfjs_model("https://ultralytics.com/images/bus.jpg")
```
=== "CLI"

View file

@ -77,18 +77,18 @@ Before diving into the usage instructions, it's important to note that while all
```python
from ultralytics import YOLO
# Load the YOLOv8 model
model = YOLO('yolov8n.pt')
model = YOLO("yolov8n.pt")
# Export the model to TFLite format
model.export(format='tflite') # creates 'yolov8n_float32.tflite'
model.export(format="tflite") # creates 'yolov8n_float32.tflite'
# Load the exported TFLite model
tflite_model = YOLO('yolov8n_float32.tflite')
tflite_model = YOLO("yolov8n_float32.tflite")
# Run inference
results = tflite_model('https://ultralytics.com/images/bus.jpg')
results = tflite_model("https://ultralytics.com/images/bus.jpg")
```
=== "CLI"

View file

@ -83,16 +83,16 @@ Before diving into the usage instructions, it's important to note that while all
from ultralytics import YOLO
# Load the YOLOv8 model
model = YOLO('yolov8n.pt')
model = YOLO("yolov8n.pt")
# Export the model to TorchScript format
model.export(format='torchscript') # creates 'yolov8n.torchscript'
model.export(format="torchscript") # creates 'yolov8n.torchscript'
# Load the exported TorchScript model
torchscript_model = YOLO('yolov8n.torchscript')
torchscript_model = YOLO("yolov8n.torchscript")
# Run inference
results = torchscript_model('https://ultralytics.com/images/bus.jpg')
results = torchscript_model("https://ultralytics.com/images/bus.jpg")
```
=== "CLI"

View file

@ -63,9 +63,9 @@ Before diving into the usage instructions for YOLOv8 model training with Weights
=== "Python"
```python
import wandb
from ultralytics import YOLO
from wandb.integration.ultralytics import add_wandb_callback
import wandb
# Step 1: Initialize a Weights & Biases run
wandb.init(project="ultralytics", job_type="training")