Rotten bananas are gross.

They're also costly: U.S. retailers throw out $18 billion worth of spoiled food each year, according to industry tracker ReFED. Most of the eight million tons of food that end up in landfills annually are the quick-to-spoil items: fruits, vegetables, meat, fish, dairy, bread.

Matt Schwartz looked at those black peels and hard rolls and saw them as an opportunity. In 2016, after years of observing the food industry's inefficiencies from the inside, he founded Afresh, a startup that uses technology to help stores figure out just how much produce to order for their shelves.

Fresh foods are harder for grocers to control than those that come in boxes or packages. They spoil fast, and they aren't stamped with bar codes or expiration dates. Their taste and freshness can vary from season to season, and so can customers' hunger for them. Even at many of the country's largest grocery chains, fresh food inventory is still measured with paper and pencil, with a manager deciding how much to order based on eyeballing and freehand calculations. U.S. grocery stores throw out about 8 percent of their fresh food on average--a number referred to in grocery industry parlance as shrink, which is a serious detriment to the bottom line.

Afresh attacks that problem with tablets and algorithms. Staffers input their inventory each day, and the startup's machine learning algorithms calculate how much of each product they should order and when. The goal is to help reduce spoilage while also ensuring that the store stocks enough supply to meet demand. 

Schwartz says that the software can pick up on deeper insights that humans might miss. Say that one particular strawberry varietal tastes especially good in mid-May--the system will learn that it tends to move quickly and will advise the store to buy more ahead of time. The company is refining more advanced insights to take into account, for instance, recent weather conditions where a certain product grows and how it's likely to affect sales.

"Fresh food is really frickin' tough. It's so dynamic," 29-year-old Schwartz says. "This helps us make decisions in a way that accounts for a lot of the uncertainty." 

Schwartz, who's a vegetarian, says he's both "obsessed with food" and "a little bit of a hippie." After graduating from the University of Southern California, he worked for the all-natural baking company Simple Mills, and then started his own snack brand, Statfoods, which he ran while getting a degree in food and agriculture at Stanford.

Schwartz and his co-founders, Nathan Fenner and Volodymyr Kuleshov, teamed up in grad school. The trio spent thousands of hours shadowing grocery store managers to learn their processes, which allowed them to build a tool that fits into existing workflows relatively seamlessly. To date, they have raised a total of $7.8 million from investors including Baseline Ventures and Innovation Endeavors. The startup says it has paid partnerships with three U.S. grocery chains. Schwartz won't name them but says two of them have more than 100 stores and billions of dollars in revenue. The company charges each store several thousand dollars each year using a subscription model.

Baseline founder Steve Anderson has seen the problem Afresh is trying to solve firsthand: Long before launching the VC firm, he worked as a regional manager at Starbucks and as a bagger at a grocery store. While contacting grocery stores during his due diligence on the startup, he says he didn't find any tech-based solutions tackling the problem on par with Afresh. Which might explain why retailers have shown so much early interest.

"They had five or six chains all clamoring to meet with them last fall," he says. ?"It's still early days, but are they in market, and are they solving a real problem that people at these grocery chains--we're talking ones with billions of dollars of revenue--want? Yes. So it's really exciting." 

Schwartz says that many of the stores participating in the pilot have cut their fresh food waste in half--which translates to serious savings. 

And, for a self-described hippie, it means a lot of good for the planet. "The future of food is fresh," he says, "and I think the world would really be better off if it were more accessible, fresher, and less wasteful."