{"id":3586,"date":"2020-08-27T00:42:31","date_gmt":"2020-08-26T19:12:31","guid":{"rendered":"https:\/\/www.suramya.com\/blog\/?p=3586"},"modified":"2022-06-16T15:19:05","modified_gmt":"2022-06-16T09:49:05","slug":"optimizing-the-making-of-peanut-butter-and-banana-sandwich-using-computer-vision-and-machine-learning","status":"publish","type":"post","link":"https:\/\/www.suramya.com\/blog\/2020\/08\/optimizing-the-making-of-peanut-butter-and-banana-sandwich-using-computer-vision-and-machine-learning\/","title":{"rendered":"Optimizing the making of peanut butter and banana sandwich using computer vision and machine learning"},"content":{"rendered":"<p>The current Pandemic is forcing people to stay at home depriving them of activities that kept them occupied in the past so people are getting a bit stir-crazy &#038; bored of staying at home. Its worse for developers\/engineers as you never know what will come out from the depths of a bored programmer&#8217;s mind. Case in point is the effort spent by <i>Ethan Rosenthal<\/i> in writing Machine Learning\/Computer Vision code to <a href=\"https:\/\/www.ethanrosenthal.com\/2020\/08\/25\/optimal-peanut-butter-and-banana-sandwiches\/\">Optimizing the coverage of the banana slices on his peanut butter &#038; Banana sandwich<\/a> so that there is the same amount of banana in every mouthful. The whole exercise took him a few months to complete and he is quite proud of the results.<\/p>\n<blockquote><p>It&#8217;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 &#8220;slice&#8221; the banana along the fitted curve, turn those slices into elliptical polygons, and feed the polygons and bread &#8220;box&#8221; into a 2D nesting algorithm<br \/>\n[\u2026]<br \/>\n    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&#8217;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 <a href=\"http:\/\/packomania.com\/\">packomania<\/a>. But alas, life is not simple. We&#8217;re in the middle of a global pandemic, and banana slices are elliptical with varying size.\n<\/p><\/blockquote>\n<p>The problem of fitting arbitrary polygons (sliced circular banana pieces) in a box (the bread piece) is NP-hard so the ideal solution is practically uncomputable and Rosenthal&#8217;s solution is a good approximation of the optimal solution in a reasonable time frame. The final solution is available as a command-line package called &#8220;<a href=\"https:\/\/github.com\/EthanRosenthal\/nannernest\">nannernest<\/a>&#8221; which takes a photo of the bread piece &#038; banana as its argument and returns the an optimal slice-and-arrange pattern for the given combination.<\/p>\n<p><center><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.suramya.com\/blog\/wp-content\/uploads\/2020\/08\/pre_made_viz_small-e1598468999312.jpg\" alt=\"\" width=\"640\" height=\"480\" class=\"alignnone size-full wp-image-3592\" \/><br \/>\nSample output created by nannernest<\/center><\/p>\n<p>Check out the <a href=\"https:\/\/github.com\/EthanRosenthal\/nannernest\">code<\/a> &#038; the <a href=\"https:\/\/www.ethanrosenthal.com\/2020\/08\/25\/optimal-peanut-butter-and-banana-sandwiches\/\">full writeup<\/a> on the project if you are interested. Even though the application is silly it&#8217;s a good writeup on using Machine Learning &#038; Computer Vision for a project.<\/p>\n<p>Source: <a href=\"https:\/\/boingboing.net\/2020\/08\/26\/optimizing-a-peanut-butter-and.html\">Boing Boing<\/a><\/p>\n<p>&#8211; Suramya<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The current Pandemic is forcing people to stay at home depriving them of activities that kept them occupied in the past so people are getting a bit stir-crazy &#038; bored of staying at home. Its worse for developers\/engineers as you never know what will come out from the depths of a bored programmer&#8217;s mind. Case [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[6,18,2],"tags":[],"class_list":["post-3586","post","type-post","status-publish","format-standard","hentry","category-computer-related","category-computer-software","category-techie-stuff"],"_links":{"self":[{"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/posts\/3586","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/comments?post=3586"}],"version-history":[{"count":4,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/posts\/3586\/revisions"}],"predecessor-version":[{"id":3593,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/posts\/3586\/revisions\/3593"}],"wp:attachment":[{"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/media?parent=3586"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/categories?post=3586"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/tags?post=3586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}