Optimizing a peanut butter and banana sandwich using machine learning and computer vision

Ethan Rosenthal is "particularly fond of peanut butter and banana sandwiches." As a data scientist, he wondered if he could "maximize the packing fraction of the banana slices," the amount of banana coverage, using computer vision and machine learning. Months later, he succeeded. Now, Rosenthal has written a deep description of the project and released the code so you too can delight in computer-optimized peanut butter and banana sandwiches. From his blog:

It's really quite simple. You take a picture of your banana and bread, pass the image through a deep learning model to locate said items, do some nonlinear curve fitting to the banana, transform to polar coordinates and "slice" the banana along the fitted curve, turn those slices into elliptical polygons, and feed the polygons and bread "box" into a 2D nesting algorithm[…]

If you were a machine learning model (or my wife), then you would tell me to just cut long rectangular strips along the long axis of the banana, but I'm not a sociopath. If life were simple, then the banana slices would be perfect circles of equal diameter, and we could coast along looking up optimal configurations on packomania. But alas, life is not simple. We're in the middle of a global pandemic, and banana slices are elliptical with varying size.

"Optimal Peanut Butter and Banana Sandwiches" (EthanRosenthal.com)