A hotel chain installs a camera in its trash bins to spy on what guests are tossing. Turns out its breakfast croissants are too big. Many are going to waste — along with profits.

A supermarket can suddenly see, hidden in its own sales data, that yellow onions aren’t selling as fast as red onions and are more likely to be trashed.

The brains behind both of these efforts: Artificial intelligence.