I’ve had the distinct displeasure of boarding a flight, and then being called by name to deplane. This happened three years ago on a flight in India from Kochi to Mumbai, and my crime was leaving a lithium-ion battery in my checked-in luggage.

If you remember the exploding Samsung Galaxy Note 7 fiasco, you may not be surprised at my moment of ignominy. Under pressure—like in the cargo holds of commercial airplanes—some lithium-ion batteries are capable of catching fire, or, worse, exploding. And these batteries, though small, can cause a lot of damage. For example, a battery 20 times the size of the one in a typical smartphone is capable of blowing out the windows of a mid-sized room.

With more people using battery packs, such as those in drones, cameras, or simply power bricks to charge the many devices we own, it’s become vital to ensure that no lithium-ion battery gets through to a plane’s cargo hold undetected. Since 1991, the US Federal Aviation Agency has reported 225 incidents (pdf) of smoke, fire, extreme heat, or explosion involving lithium-ion batteries in cargo or baggage.

The way to catch stray lithium-ion batteries is to blast X-rays on the luggage. When exposed, the electromagnetic radiation passes through and bounces off various things inside the bag differently depending on the density of the many types of material. Detectors collect these X-rays and create an image of what’s inside the bag.

Most airports use some form of software to help aid the process, but human intervention is needed and that makes the process prone to errors. To help cut down on those mistakes, Smiths Detection, a multinational supplier of X-ray detectors at airports, built software they claim can drastically cut the need for human input. It uses a deep-learning algorithm to improve the rate of detection to up to 90%, the company says.

Smiths Detection Black-and-white squares show what the algorithm thinks is a lithium-ion battery.

Smiths’ deep-learning algorithm takes feedback from its successes and failures and refines its method moving forward using data on the shapes, textures, and materials that accurately indicate the presence of a lithium-ion battery. It’s self-updating, so it learns and improves on the fly. And because it’s a software upgrade, the company can deploy its technology on already-existing Smiths detectors.

To create the algorithm, Smiths used a large database of X-ray images collected during live operation at a customer site. Next, the company manually tagged those images as containing lithium-ion batteries or not.”Obtaining this kind of comprehensive, labeled data set for training is the most resource-intensive part of the deep-learning process,” says Matt Clark, Smiths’ vice president of technology and product development.

The deep-learning software was then trained using this data and tested against the manually tagged database. That’s how it learned from its successes and failures to start with, and it continues to do that in live operations across the world.

Smiths plans to adapt its software to also detect drugs, weapons, currency, and flammable liquids. Faster and more accurate detection of all sorts of contraband will not just improve airport security and save money, but also perhaps end the practice of having to shame a passenger for having made a genuine mistake.