How to Use Ultralytics YOLOv8 for Object Detection

May 23, 2024 | Educational

In this article, we’ll explore how to effectively use the Ultralytics YOLOv8 model, specifically tailored for detecting planes using the keremberke plane-detection dataset. Let’s embark on this exciting journey to understand how to set up everything and get predictions step by step!

What You Need

  • Python installed on your machine
  • Access to a command line interface (CLI) or terminal
  • Basic knowledge of Python libraries

Step 1: Installation

We need to first install the required libraries. Open your terminal and execute the following command:

bash
pip install ultralyticsplus==0.0.23 ultralytics==8.0.21

Step 2: Load the Model and Set Parameters

Now that the libraries are installed, it’s time to load our model for detection. The following code snippet will guide you through:

python
from ultralyticsplus import YOLO, render_result

# Load the model
model = YOLO('keremberkeyolov8s-plane-detection')

# Set model parameters
model.overrides['conf'] = 0.25  # NMS confidence threshold
model.overrides['iou'] = 0.45  # NMS IoU threshold
model.overrides['agnostic_nms'] = False  # NMS class-agnostic
model.overrides['max_det'] = 1000  # Maximum number of detections per image

Think of the model as a skilled security guard at an airport. The confidence threshold is like the guard’s intuition to only take action if they feel 25% sure that something is suspicious. The IoU threshold ensures that two objects aren’t mistakenly detected when they are too close. One can also set limits on how many objects (in this case, planes) the guard should keep an eye on by adjusting the maximum detections per image.

Step 3: Set the Image for Prediction

Now, we need to provide an image for the model to analyze. Here’s how to set up the image:

# Set image
image = 'https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg'

Step 4: Perform Inference

Once we have the image ready, we can perform the actual detection. This is a straightforward step as shown below:

# Perform inference
results = model.predict(image)

# Observe results
print(results[0].boxes)
render = render_result(model=model, image=image, result=results[0])
render.show()

Here, performing inference is akin to asking our attentive airport guard to check for any suspicious individuals based on the provided image. The results will show which planes are detected along with their positions.

Supported Labels

  • Planes

Troubleshooting Tips

If you encounter any issues while using the Ultralytics YOLOv8 model, here are a few tips to help you troubleshoot:

  • Make sure you are using the correct versions of the libraries: ultralyticsplus==0.0.23 and ultralytics==8.0.21. Mismatched versions might cause unexpected errors.
  • Check your internet connection when trying to load images from URLs to ensure they are reachable.
  • If the model isn’t performing as expected, try adjusting the confidence or IoU thresholds to better suit your dataset.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Final Thoughts

Using the Ultralytics YOLOv8 model for object detection can open up exciting possibilities in recognizing and analyzing objects within images. With proper setups and adjustments, you can enhance detection accuracy and make meaningful use of AI technology.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox