Detecting the presence of birds, and identifying their species, has a range of use cases. Nature conservation organizations can use cameras to identify birds in conservation areas. Apps can identify different species of birds, helping to connect people to the nature around them.

Roboflow Universe, a repository of over 110,000 public datasets and 11,000 trained models for use in computer vision projects, provides an open, free-to-use API that detects around 30 bird species, from blue jays to song sparrows. This model could be adapted to identify a greater number of species by using the underlying dataset and adding new annotated images with the birds that you want the model to be able to identify.

In this guide, we're going to show how to use a bird detection model on Roboflow Universe to identify the location of birds in an image. At the end of this guide, we will have a Python script that retrieves the coordinates of predictions made on an image and draws boxes on the provided image to visually represent the identifications made. Here is what this will look like:

Without further ado, let's get started!

Using the Bird Detection API

The bird detection API that we will use in this post is called "bird v2." This API is hosted on Roboflow Universe. To retrieve predictions from the model, you must have a Roboflow account. You can create one for free. After you create your account, you will be issued an API key that you can use to access publicly-available models on Universe.

Before we begin writing a script to retrieve predictions from the API, we are going to test the model to make sure it meets our needs. As aforementioned, the model only detects the species of around 30 birds, but you can download the dataset and add new images to train the model to identify more species.

This model achieves an 89.7% mAP score and a 90.3% precision score.

To test the model, go to the bird detection page on Roboflow Universe then click "Model" in the sidebar. This page contains an interactive widget you can use to test the model. This widget supports testing the model by using:

  • Images from the dataset test set;
  • Images or videos accessible by URL;
  • Images or videos you upload onto the page and;
  • Your browser webcam.

Once you have experimented with the API in the testing environment on Universe, you're ready to start using the API in an application. For this guide, we'll use the Roboflow Python SDK. This SDK will let you "run inference" (retrieve predictions from a model) in a few lines of code. To get started, create a new file called "app.py". Scroll down to the "Infer on Local and Hosted Images" section on the model page on Universe, and copy the provided code snippet into your new app.py file.

This code snippet will look like this:

from roboflow import Roboflow

rf = Roboflow(api_key="YOUR_API_KEY")
project = rf.workspace().project("bird-v2")
model = project.version(2).model

# infer on a local image
print(model.predict("your_image.jpg", confidence=40, overlap=30).json())

model.predict("your_image.jpg", confidence=40, overlap=30).save("prediction.jpg")

Remove the comment from the "visualize your prediction" line of code at the end of the script. This line of code will create a new image file that contains boxes that show where the model identified birds. After you have added this code to your script, run the script. This script will:

  1. Print a JSON object to the console that contains information on all predictions and;
  2. Create a new prediction.jpg file that shows all of our predictions on our image.

Let's test the script on this image:

After running the script, we get this JSON object that shows our predictions:

{'predictions': [{'x': 494.0, 'y': 308.5, 'width': 258.0, 'height': 209.0, 'confidence': 0.8964624404907227, 'class': 'orchard-oriole', 'image_path': 'original.jpg', 'prediction_type': 'ObjectDetectionModel'}], 'image': {'width': 800, 'height': 533}}

The "prediction.jpg" file looks like this:

We can see that our model has successfully identified that the pictured bird is an Orchard Oriole. Great!

Deploying the Model to Production

With a working model ready, the next step is to consider the best method of deployment for your use case. Roboflow provides a range of SDKs that reduce the friction associated with using your model in code. The Roboflow documentation contains extensive detail on the options available. Here are some of the most common deployment methods used:

  • Web browser: Run a model in your browser using JavaScript and roboflow.js.
  • iOS: Deploy a model for use in a native iOS application.
  • NVIDIA Jetson: Run your model on a purpose-built edge computing device. Ideal for applications that need more computing power.
  • Raspberry Pi: Run your model on a computer with a small form factor
  • Luxonis OAK: Use your model on an edge inference device with a camera and a range of other functionalities built in (i.e. depth capabilities).
  • Python SDK: Used earlier, the Roboflow Python SDK provides abstract functions to run inference a model hosted on Roboflow in your Python applications.

Use Cases for the Bird Detection Model

At the beginning of this article, we noted a few of the use cases for a bird detection model. Both hobbyists and conservation professionals alike can leverage a bird detection model. For example, you could:

  1. Use a bird detection model to collect data about the birds in your garden;
  2. Track how many times a certain species of bird appears in a nature reserve;
  3. Record what species of birds are most common in a specific area at different times of the year;
  4. Create an interactive and fun application that helps kids learn more about the birds around them;
  5. And more!

Depending on your use case, you may want to improve the underlying detection model to suit your needs. You can learn more about creating your own model in this guide:

For instance, if you are a nature organization looking to montior at-risk species, you may opt to train a new model to identify only those species; if you are building a bird identification app, you may want to copy the model we have been using and add more data to increase the utility of the application.

Conclusion

In this guide, we have walked through how to use a bird detection model hosted on Roboflow Universe to identify the species of bird in an image. We demonstrated how to use the Roboflow Universe inference widget to test a bird detection model. We then wrote a short Python script that queries the Roboflow API and runs inference on an image.

We retrieved both a JSON representation of all predictions as well as an image that shows all of our predictions. We also discuss the range of deployment options available using the model, and some potential use cases for the model.

We encourage you to explore ideas and let your creativity flow; the utiliity of nature detection systems like bird species classifiers is great. Happy building!