Identifying Plants with AI

For Laypersons and Programmers

Nuwan I. Senaratna
On Technology
4 min readMar 9, 2024

--

Do you know what tree this is? If you are a Sri Lankan, you should know. But if not, no bother.

Read on, and you will learn how to identify it. And any other plant.

Wikipedia

For Laypersons

Pl@ntNet is a citizen science project for automatic plant identification through photographs and based on machine learning.

This project launched in 2009 has been developed by scientists (computer engineers and botanists) from a consortium gathering French research institutes (Institut de recherche pour le développement (IRD), Centre de coopération internationale en recherche agronomique pour le développement (CIRAD), Institut national de la recherche agronomique (INRA), Institut national de recherche en informatique et en automatique (INRIA) and the network Tela Botanica, with the support of Agropolis Fondation). — Pl@ntNet — Wikipedia

To identify a plant, go to https://identify.plantnet.org/ and drag-and-drop a picture of a tree, leaf or flower.

Pl@ntNet identify (plantnet.org)

And that’s it.

In seconds, you will get a list of “guesses” on what the plant might be. The top guess for the photo I showed you was Mesua ferrea. The guess has a 88.5% confidence, which means that the AI is very sure.

If you didn’t already know, Mesua ferrea commonly known as Na (නා), Mesua, Iron Wood Tree, Ceylon Ironwood, Indian Rose Chestnut, and Penaga Lili. It is the national tree of Sri Lanka. A bit of trivia: It is also the state tree of the Indian stage of Mizoram. The Mesua flower is the state flower of the Indian state of Tripura.

You can click through for more information.

For Programmers

If, like me, you are a Computer Scientist, you might be wonder if it was possible to do this at scale. For example, what if you could provide a list of photos, make an API call, and get a JSON blurb with all the above data.

PlantNet let’s you do exactly that. Let’s see how.

1️⃣First, go to https://my.plantnet.org/ and sign-up for an account.

The Free Plan lets you make 500 identifications per day. If you need more, you could sign up for the Pro Plan. If you are a Non-Profit, you can get a more flexible plan.

2️⃣After you have created your account, and confirmed your email, go to the Settings page (https://my.plantnet.org/account/settings), and copy you API_KEY.

The PlantNet API has several functions, which you can try out on the API page (https://my.plantnet.org/doc/openapi).

3️⃣We can identify the photo above using the API call identify, as follows:

Note: The URL of the photo above is:

https://upload.wikimedia.org/wikipedia/commons/d/d7/Mesua_ferrea_%28Ceylon_ironwood%29%E2%80%93_the_red_leaves_of_new_growth.jpg

Click “Execute” and you will see the output rendered as JSON.

Alternatively, you could make the API call with CURL:


curl -X 'GET' \
'https://my-api.plantnet.org/v2/identify/all?images=https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fd%2Fd7%2FMesua_ferrea_%2528Ceylon_ironwood%2529%25E2%2580%2593_the_red_leaves_of_new_growth.jpg&include-related-images=false&no-reject=false&lang=en&api-key=<YOUR_API_KEY>' \
-H 'accept: application/json'

Or on your browser with a URL

https://my-api.plantnet.org/v2/identify/all?images=https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fd%2Fd7%2FMesua_ferrea_%2528Ceylon_ironwood%2529%25E2%2580%2593_the_red_leaves_of_new_growth.jpg&include-related-images=false&no-reject=false&lang=en&api-key=<YOUR_API_KEY>

The API has various options. For example, you can provide multiple images. You can also optionally specify which part of the tree your photo is of (e.g. leaf, flower, fruit or bark), for more accurate identifition. You can also specify where your tree is located. For more details, see https://my.plantnet.org/doc/openapi.

You can also access the API programmatically, e.g. with Python.

import requests
import json
from pprint import pprint

API_KEY = "" # Set you API_KEY here
PROJECT = "all" # try "weurope" or "canada"
api_endpoint = f"https://my-api.plantnet.org/v2/identify/{PROJECT}?api-key={API_KEY}"


image_path_1 = "../data/image_1.jpeg"
image_data_1 = open(image_path_1, 'rb')

image_path_2 = "../data/image_2.jpeg"
image_data_2 = open(image_path_2, 'rb')


data = {
'organs': ['flower', 'leaf']
}

files = [
('images', (image_path_1, image_data_1)),
('images', (image_path_2, image_data_2))
]

req = requests.Request('POST', url=api_endpoint, files=files, data=data)
prepared = req.prepare()

s = requests.Session()
response = s.send(prepared)
json_result = json.loads(response.text)

pprint(response.status_code)
pprint(json_result)

You can find more code examples at: https://github.com/plantnet/my.plantnet.

Concluding Caveats

Identifying plants can, at times, be fiendishly difficult. Even human experts often make mistakes. Hence, note that the AI can and will make mistakes.

--

--

Nuwan I. Senaratna
On Technology

I am a Computer Scientist and Musician by training. A writer with interests in Philosophy, Economics, Technology, Politics, Business, the Arts and Fiction.