{"id":950,"date":"2020-11-07T14:00:04","date_gmt":"2020-11-07T14:00:04","guid":{"rendered":"https:\/\/thenextweb.com\/?p=1326883"},"modified":"2020-11-07T14:00:04","modified_gmt":"2020-11-07T14:00:04","slug":"how-to-build-an-ai-stylist-inspired-by-outfits-on-instagram","status":"publish","type":"post","link":"https:\/\/www.londonchiropracter.com\/?p=950","title":{"rendered":"How to build an AI stylist inspired by outfits on Instagram"},"content":{"rendered":"\n<p>Last year, in a universe where it still made sense to owns pants, I decided to hire a personal stylist.<\/p>\n<p>In our first appointment, the stylist came to my apartment and took pictures of every clothing item I owned.<\/p>\n<p>In our second appointment, she met me at Nordstrom\u2019s, where she asked me to try on a $400 casual dress, a $700 blazer, and $300 sneakers. (I never thought to ask if she worked on commission.)<\/p>\n<p>But only after our third and final appointment, when she finally sent me a folder full of curated \u201clooks\u201d made from my new and old clothing items, did it finally click: I\u2019d just blown a<span>&nbsp;<\/span><em>lot<\/em>&nbsp;of money.<\/p>\n<p>I had a suspicion we were on different pages when, as we walked through the shoes section at Nordstrom, the stylist said, \u201cThe problem with you people in tech is that you\u2019re always looking for some kind of theory or strategy or formula for fashion<em>.<\/em><span>&nbsp;<\/span>But there is no formula\u2013it\u2019s about<span>&nbsp;<\/span><em>taste<\/em>.<em>\u201d<\/em><\/p>\n<p>Pfffft. We\u2019ll see about<span>&nbsp;<\/span><em>that<\/em>!<\/p>\n<p>I returned the pricey clothing and decided to build my own (cheaper!) AI-powered stylist. In this post, I\u2019ll show you how you can, too.<\/p>\n<p><em>Want to see a video version of this post? Check out it <a href=\"https:\/\/www.youtube.com\/watch?v=o6nGn1euRjk&amp;feature=emb_title\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">here<\/a>.<\/em><\/p>\n<p>My AI Stylist was half based on this smart closet from the movie<span>&nbsp;<\/span><em>Clueless<\/em>:<\/p>\n<p>and half based on the idea that one way to dress fashionably is to copy fashionable people. Particularly, fashionable people on Instagram.<\/p>\n<p>The app pulls in the Instagram feeds of a bunch of fashion \u201cinfluencers\u201d on Instagram and combines them with pictures of clothing you already own to recommend you outfits. Here\u2019s what it looks like:<\/p>\n<p><img decoding=\"async\" title=\"AI Stylist UI\" src=\"https:\/\/daleonai.com\/images\/mismatch_ui.png\" alt=\"Screenshot of the AI Stylist\" class=\" lazy\" data-lazy=\"true\"><\/p>\n<p>(You can also check out the live app&nbsp;<a href=\"http:\/\/mismatch.daleonai.com\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">here<\/a>.)<\/p>\n<p>On the left pane\u2013the closet screen\u2013you can see all the clothing items I already own. On the right pane, you\u2019ll see a list of Instagram accounts I follow for inspiration. In the middle pane (the main screen), you can see the actual outfit recommendations the AI made for me. The Instagram inspiration picture is at the top, and items for my closet are shown below:<\/p>\n<p><img decoding=\"async\" title=\"Outfits recommended by the AI Stylist\" src=\"https:\/\/daleonai.com\/images\/mismatch.gif\" alt=\"Screenshot of swiping through outfit recommendations in the app\" class=\" lazy\" data-lazy=\"true\"><\/p>\n<p>Here my style muse is Laura Medalia, an inspiring software developer who\u2019s<span>&nbsp;<\/span><a href=\"https:\/\/www.instagram.com\/codergirl_\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@codergirl_<\/a><span>&nbsp;<\/span>on Instagram (make sure to follow her for fashion and tips for working in tech!).<\/p>\n<p>The whole app took me about a month to build and cost ~$7.00 in Google Cloud credits (more on pricing later). Let\u2019s dive in.<\/p>\n<h2 id=\"the-architecture\">The architecture<\/h2>\n<p>I built this app using a combination of<span>&nbsp;<\/span><a href=\"https:\/\/cloud.google.com\/storage\/?utm_source=google&amp;utm_medium=cpc&amp;utm_campaign=na-US-all-en-dr-bkws-all-all-trial-e-dr-1009135&amp;utm_content=text-ad-none-any-DEV_c-CRE_79747411687-ADGP_Hybrid+%7C+AW+SEM+%7C+BKWS+%7C+US+%7C+en+%7C+EXA+~+Google+Cloud+Storage-KWID_43700007031545851-kwd-11642151515&amp;utm_term=KW_google%20cloud%20storage-ST_google+cloud+storage&amp;gclid=CjwKCAjww5r8BRB6EiwArcckC8WRFN95onXmZi1ly_pfNslOQMjZ6Ex03ypCr7irmeuzPsrDydBL8xoCUV8QAvD_BwE\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google Cloud Storage<\/a>,<span>&nbsp;<\/span><a href=\"https:\/\/daleonai.com\/firebase.com\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Firebase<\/a>, and Cloud Functions for the backend,<span>&nbsp;<\/span><a href=\"https:\/\/reactjs.org\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">React<\/a><span>&nbsp;<\/span>for the frontend, and the<span>&nbsp;<\/span><a href=\"https:\/\/goo.gle\/3e61wwb\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google Cloud Vision API<\/a><span>&nbsp;<\/span>for the ML bits. I divided the architecture into two bits.<\/p>\n<p>First, there\u2019s the<span>&nbsp;<\/span><em>batch process<\/em>, which runs every hour (or however frequently you like) in the Cloud:<\/p>\n<p><img decoding=\"async\" title=\"The \\\\&quot;batch process\\\\&quot; makes outfit recommendations using AI\" src=\"https:\/\/daleonai.com\/images\/pxl_20201014_203905793.jpg\" alt=\"Diagram of batch process for making outfit recommendations\" class=\" lazy\" data-lazy=\"true\"><\/p>\n<p>\u201cBatch process\u201d is just a fancy way of saying that I wrote a Python script which runs on a scheduled interval (more on that later). The process:<\/p>\n<ol>\n<li>Pulls photos from social media<\/li>\n<li>Uses the Vision API\u2019s<span>&nbsp;<\/span><a href=\"https:\/\/goo.gle\/3otRoCi\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Product Search<\/a><span>&nbsp;feature<\/span> to find similar items in my closet<\/li>\n<li>Scores the matches (i.e. of all the social media pictures, which can I most accurately recreate given clothing in my closet?)<\/li>\n<li>Writes the matches to<span>&nbsp;<\/span><a href=\"https:\/\/firebase.google.com\/docs\/firestore\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Firestore<\/a>\n<\/li>\n<\/ol>\n<p>This is really the beefy part of the app, where all the machine learning magic happens. The process makes outfit recommendations and writes them to Firestore, which is my favorite ever lightweight database for app development (I use it in almost all my projects).<\/p>\n<p>The actual<span>&nbsp;<\/span><em>app<\/em>&nbsp;(in this case, just a responsive web app) is simple: it just reads the outfit recommendations from Firestore and displays them in a pretty interface:<\/p>\n<p><img decoding=\"async\" title=\"The web app just displays data from Firestore\" src=\"https:\/\/daleonai.com\/images\/pxl_20201014_204154884.jpg\" alt=\"Architecture diagram of a web app reading from Firestore\" class=\" lazy\" data-lazy=\"true\"><\/p>\n<p>Let\u2019s take a look!<\/p>\n<p>Ideally, I wanted my app to pull pictures from Instagram automatically, based on which accounts I told it to follow. Unfortunately, Instagram doesn\u2019t have an API (and using a<span>&nbsp;<\/span><a href=\"https:\/\/github.com\/arc298\/instagram-scraper\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">scraper<\/a><span>&nbsp;<\/span>would violate their TOS). So I specifically asked Laura for permission to use her photos. I downloaded them to my computer and then uploaded them to a<span>&nbsp;<\/span><a href=\"https:\/\/cloud.google.com\/storage\/?utm_source=google&amp;utm_medium=cpc&amp;utm_campaign=na-US-all-en-dr-bkws-all-all-trial-e-dr-1009135&amp;utm_content=text-ad-none-any-DEV_c-CRE_79747411447-ADGP_Hybrid+%7C+AW+SEM+%7C+BKWS+%7C+US+%7C+en+%7C+EXA+~+Google+Cloud+Storage-KWID_43700007031545851-kwd-11642151515&amp;utm_term=KW_google%20cloud%20storage-ST_google+cloud+storage&amp;gclid=CjwKCAjw5p_8BRBUEiwAPpJO6xIv5t69bTUdDMVgY_7hC04hj1xyRz-o90_T3a332_F-QUqmofOeqhoCneUQAvD_BwE\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google Cloud Storage bucket<\/a>:<\/p>\n<div class=\"language-shell highlighter-rouge\" readability=\"6.5\">\n<div class=\"highlight\" readability=\"8\">\n<pre class=\"highlight\"><code><span class=\"c\"># Create a cloud storage bucket<\/span> gsutil mb gs:\/\/inspo-pics-bucket <span class=\"c\"># Upload inspiration pics <\/span> gsutil <span class=\"nb\">cp <\/span>path\/to\/inspo\/pics\/<span class=\"k\">*.jpg<\/span> gs:\/\/inspo-pics-bucket <\/code><\/pre>\n<\/div>\n<\/div>\n<h2 id=\"filtering-for-fashion-pics\">Filtering for fashion pictures<\/h2>\n<p>I like Laura\u2019s account for inspiration because she usually posts pictures of herself in head-to-toe outfits (shoes included). But some pics on her account are more like this:<\/p>\n<p><img decoding=\"async\" title=\"Laura's cute pooch\" src=\"https:\/\/daleonai.com\/images\/doggy.jpg\" alt=\"Dog in front of a laptop\" class=\" lazy\" data-lazy=\"true\"><\/p>\n<p>Adorable, yes, but I can\u2019t personally pull off the dressed-in-only-a-collar look. So I needed some way of knowing which pictures contained outfits (worn by people) and which didn\u2019t.<\/p>\n<p>For that, I turned to my trusty steed, the&nbsp;<a href=\"https:\/\/goo.gle\/3e61wwb\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google Cloud Vision API<\/a>&nbsp;(which I use in many different ways for this project). First, I used its&nbsp;classification&nbsp;feature, which assigns labels to an image. Here\u2019s the labels it gives me for a picture of myself, trying to pose as an influencer:<\/p>\n<p><img decoding=\"async\" title=\"The Vision API returns lots of labels for this photo\" src=\"https:\/\/daleonai.com\/images\/screen-shot-2020-10-15-at-11.43.18-am.png\" alt=\"Screenshot of the Vision API analyzing an outfit\" class=\" lazy\" data-lazy=\"true\"><\/p>\n<p>The labels are ranked by how confident the model is that they\u2019re relevant to the picture. Notice there\u2019s one label called \u201cFashion\u201d (confidence 90%). To filter Laura\u2019s pictures, I labeled them all with the Vision API and removed any image that didn\u2019t get a \u201cFashion\u201d label. Here\u2019s the code:<\/p>\n<p><figure class=\"post-image post-mediaBleed alignnone\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1326884 lazy\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.04.39-PM.png\" alt width=\"761\" height=\"525\" sizes=\"(max-width: 761px) 100vw, 761px\" data-lazy=\"true\" data-srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.04.39-PM.png 761w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.04.39-PM-280x193.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.04.39-PM-391x270.png 391w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.04.39-PM-196x135.png 196w\"><\/figure>\n<\/p>\n<p>If you want the full code, check it out<span>&nbsp;<\/span><a href=\"https:\/\/github.com\/google\/making_with_ml\/tree\/master\/instafashion\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">here<\/a>.<\/p>\n<h2 id=\"digitizing-my-closet\">Digitizing my closet<\/h2>\n<p>Now the goal is to have my app look at Laura\u2019s fashion photos and recommend me items in my closet I can use to recreate them. For that, I had to take a pictures of item of clothing I owned, which would have been a pain except I happen to have a very lean closet.<\/p>\n<p>I hung each item up on my mannequin and snapped a pic.<\/p>\n<p><img decoding=\"async\" title=\"Photographing clothing for my dataset\" src=\"https:\/\/daleonai.com\/images\/photos_of_closet.gif\" alt=\"gif of trying different outfits on a mannequin and taking pictures\" class=\" lazy\" data-lazy=\"true\"><\/p>\n<h2 id=\"using-the-vision-product-search-api\">Using the vision product search API<\/h2>\n<p>Once I had all of my fashion inspiration pictures and my closet pictures, I was ready to start making outfit recommendations using the<span>&nbsp;<\/span><a href=\"https:\/\/goo.gle\/3otRoCi\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google Vision Product Search API<\/a>.<\/p>\n<p>This API is designed to power features like \u201csimilar product search.\u201d Here\u2019s an example from the Pinterest app:<\/p>\n<p><img decoding=\"async\" title=\"Screenshot of Pinterest's similar item search feature\" src=\"https:\/\/daleonai.com\/images\/pinterest.png\" alt=\"Screenshot of Pinterest's similar item search feature\" class=\" lazy\" data-lazy=\"true\"><\/p>\n<p>IKEA also built a nice demo that allows customers to search their products via images with this kind of tech:<\/p>\n<p><img decoding=\"async\" title=\"Original image from TechCrunch\" src=\"https:\/\/daleonai.com\/images\/ikea_gif.gif\" alt=\"Video of customer searching an IKEA product catalog by photo\" class=\" lazy\" data-lazy=\"true\"><\/p>\n<p>I\u2019m going to use the Product Search API in a similar way, but instead of connecting a product catalog, I\u2019ll use my own wardrobe, and instead of recommend similar individual<span>&nbsp;<\/span><em>items<\/em>, I\u2019ll recommend entire outfits.<\/p>\n<p>To use this API, you\u2019ll want to:<\/p>\n<ol>\n<li>Uploading your closet photos to Cloud Storage<\/li>\n<li>Create a new Product Set using the Product Search API<\/li>\n<li>Create a new product for each item in your closet<\/li>\n<li>Upload (multiple) pictures of those products<\/li>\n<\/ol>\n<p>At first I attempted this using the<span>&nbsp;<\/span><a href=\"https:\/\/cloud.google.com\/vision\/product-search\/docs\/libraries?utm_campaign=dama_awareness_visionprod_102620&amp;utm_source=da&amp;utm_medium=blog\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">official Google Python client library<\/a>, but it was a bit clunky, so I ended up writing my own Python Product Search wrapper library, which you can find<span>&nbsp;<\/span><a href=\"https:\/\/pypi.org\/project\/pyvisionproductsearch\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">here<\/a><span>&nbsp;<\/span>(on PyPi). Here\u2019s what it looks like in code:<\/p>\n<p><figure class=\"post-image post-mediaBleed alignnone\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1326885 lazy\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.05.04-PM.png\" alt width=\"795\" height=\"669\" sizes=\"(max-width: 795px) 100vw, 795px\" data-lazy=\"true\" data-srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.05.04-PM.png 795w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.05.04-PM-250x210.png 250w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.05.04-PM-321x270.png 321w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.05.04-PM-160x135.png 160w\"><\/figure>\n<\/p>\n<p>Note this wrapper library&nbsp;<strong>handles uploading photos to a Cloud Storage bucket automatically<\/strong>, so you can upload a new clothing item to your product set from a local image file:<\/p>\n<p><figure class=\"post-image post-mediaBleed alignnone\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1326886 lazy\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.05.29-PM.png\" alt width=\"765\" height=\"155\" sizes=\"(max-width: 765px) 100vw, 765px\" data-lazy=\"true\" data-srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.05.29-PM.png 765w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.05.29-PM-280x57.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.05.29-PM-540x109.png 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.05.29-PM-270x55.png 270w\"><\/figure>\n<\/p>\n<div class=\"highlight\" readability=\"10.850801479655\">\n<p>If you, dear reader, want to make your own product set from your own closet pics, I wrote a<span>&nbsp;<\/span><a href=\"https:\/\/github.com\/google\/making_with_ml\/blob\/master\/instafashion\/scripts\/product_set_from_dir.py\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Python script<\/a><span>&nbsp;<\/span>to help you make a product set from a folder on your desktop. Just:<\/p>\n<ol>\n<li>Download the code from GitHub and navigate to the instafashion\/scripts folder:<\/li>\n<\/ol>\n<p><figure class=\"post-image post-mediaBleed alignnone\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1326887 lazy\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.05.43-PM.png\" alt width=\"763\" height=\"154\" sizes=\"(max-width: 763px) 100vw, 763px\" data-lazy=\"true\" data-srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.05.43-PM.png 763w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.05.43-PM-280x57.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.05.43-PM-540x109.png 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.05.43-PM-270x54.png 270w\"><\/figure>\n<\/p>\n<ol>\n<li>Create a new folder on your computer to store all your clothing items (mine\u2019s called<span>&nbsp;<\/span><code class=\"language-plaintext highlighter-rouge\">my_closet<\/code>):<\/li>\n<\/ol>\n<p><figure class=\"post-image post-mediaBleed alignnone\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1326888 lazy\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.06.02-PM.png\" alt width=\"765\" height=\"85\" sizes=\"(max-width: 765px) 100vw, 765px\" data-lazy=\"true\" data-srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.06.02-PM.png 765w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.06.02-PM-280x31.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.06.02-PM-540x60.png 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.06.02-PM-270x30.png 270w\"><\/figure>\n<\/p>\n<ol>\n<li>Create a new folder for each clothing item and put all of your pictures of that item in the folder:<\/li>\n<\/ol>\n<div class=\"language-shell highlighter-rouge\" readability=\"31.626666666667\">\n<div class=\"highlight\">\n<figure class=\"post-image post-mediaBleed alignnone\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1326889 lazy\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/local_closet.gif\" alt width=\"1137\" height=\"606\" data-lazy=\"true\"><\/figure>\n<\/div>\n<div class=\"highlight\" readability=\"63.7475\">\n<p>So in the gif above, all my black bomber pics are in a folder named<span>&nbsp;<\/span><code class=\"language-plaintext highlighter-rouge\">black_bomber_jacket<\/code>.<\/p>\n<p>To use my script, you\u2019ll have to name your product folders using the following convention:<span>&nbsp;<\/span><code class=\"language-plaintext highlighter-rouge\">name_of_your_item_shoe<\/code><span>&nbsp;<\/span>where<span>&nbsp;<\/span><code class=\"language-plaintext highlighter-rouge\">shoe<\/code><span>&nbsp;<\/span>can be any of<span>&nbsp;<\/span><code class=\"language-plaintext highlighter-rouge\">[skirt, dress, jacket, top, shoe, shorts, scarf, pants]<\/code>.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/daleonai.com\/images\/screen-shot-2020-10-28-at-4.49.16-pm.png\" alt class=\" lazy\" data-lazy=\"true\"><\/p>\n<ol>\n<li>After creating your directory of product photos, you\u2019ll need to set up some config by editing the `.env_template` file:<\/li>\n<\/ol>\n<p><figure class=\"post-image post-mediaBleed alignnone\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1326890 lazy\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.06.44-PM.png\" alt width=\"758\" height=\"223\" sizes=\"(max-width: 758px) 100vw, 758px\" data-lazy=\"true\" data-srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.06.44-PM.png 758w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.06.44-PM-280x82.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.06.44-PM-540x159.png 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.06.44-PM-270x79.png 270w\"><\/figure>\n<\/p>\n<p>(Oh, by the way: you need to have a Google Cloud account to use this API! Once you do, you can create a new project and download a credentials file.)<\/p>\n<ol>\n<li>Then install the relevant Python libraries and run the script<span>&nbsp;<\/span><code class=\"language-plaintext highlighter-rouge\">product_set_from_dir.py<\/code>:<\/li>\n<\/ol>\n<p><figure class=\"post-image post-mediaBleed alignnone\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1326891 lazy\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.07.02-PM.png\" alt width=\"765\" height=\"121\" sizes=\"(max-width: 765px) 100vw, 765px\" data-lazy=\"true\" data-srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.07.02-PM.png 765w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.07.02-PM-280x44.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.07.02-PM-540x85.png 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.07.02-PM-270x43.png 270w\"><\/figure>\n<\/p>\n<p>Phew, that was more steps than I thought!<\/p>\n<p>When you run that Python script,<span>&nbsp;<\/span><code class=\"language-plaintext highlighter-rouge\">product_set_from_dir.py<\/code>, your clothing photos get uploaded to the cloud and then processed or \u201cindexed\u201d by the Product Search API. The indexing process can take up to 30 minutes, so go fly a kite or something.<\/p>\n<h2 id=\"searching-for-similar-items\">Searching for similar items<\/h2>\n<p>Once your product set is done indexing, you can start using it to search for similar items. Woohoo! \ud83c\udf8a<\/p>\n<p>In code, just run:<\/p>\n<p><figure class=\"post-image post-mediaBleed alignnone\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1326892 lazy\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.07.31-PM.png\" alt width=\"733\" height=\"646\" sizes=\"(max-width: 733px) 100vw, 733px\" data-lazy=\"true\" data-srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.07.31-PM.png 733w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.07.31-PM-238x210.png 238w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.07.31-PM-306x270.png 306w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.07.31-PM-153x135.png 153w\"><\/figure>\n<\/p>\n<p><figure class=\"post-image post-mediaBleed alignnone\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1326893 lazy\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.07.42-PM.png\" alt width=\"733\" height=\"494\" sizes=\"(max-width: 733px) 100vw, 733px\" data-lazy=\"true\" data-srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.07.42-PM.png 733w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.07.42-PM-280x189.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.07.42-PM-401x270.png 401w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.07.42-PM-200x135.png 200w\"><\/figure>\n<\/p>\n<p>The response contains lots of data, including which items were recognized in a the source photo (i.e. \u201cskirt\u201d, \u201ctop\u201d) and what items in your project set matched with them. The API also returns a \u201cscore\u201d field for each match which tells you how confident the the API is that an item in your product set matched the picture.<\/p>\n<h2 id=\"from-matching-items-to-matching-outfits\">From matching items to marching outfits<\/h2>\n<p>The Product Search API looks at an inspiration picture (in this case, Laura\u2019s fashion pics) and finds similar items in my wardrobe. But what I really want to do is put together whole<span>&nbsp;<\/span><em>outfits<\/em>, which consist of a single top, a single pair of pants, a single set of shoes, etc. Sometimes the Product Search API doesn\u2019t return a logical outfit. For example, if Laura is wearing a long shirt that looks like it could<span>&nbsp;<\/span><em>almost<\/em><span>&nbsp;<\/span>be a dress, the API might return both a similar shirt and dress in my wardrobe. To get around that, I had to write my own outfit logic algorithm to build an outfit from the Search API results:<\/p>\n<div class=\"highlight\">\n<figure class=\"post-image post-mediaBleed alignnone\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1326894 lazy\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.08.04-PM.png\" alt width=\"764\" height=\"359\" sizes=\"(max-width: 764px) 100vw, 764px\" data-lazy=\"true\" data-srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.08.04-PM.png 764w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.08.04-PM-280x132.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.08.04-PM-540x254.png 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.08.04-PM-270x127.png 270w\"><\/figure>\n<\/div>\n<div readability=\"26.735605559232\">\n<h2 id=\"scoring-outfits\">Scoring outfits<\/h2>\n<p>Naturally, I couldn\u2019t recreate every one of Laura\u2019s outfits using only items in my limited wardrobe. So I decided my approach would be to look at the outfits I could most accurately recreate (using the confidence scores returned by the Product Search API) and create a \u201cscore\u201d to sort the recommended outfits.<\/p>\n<p>Figuring out how to \u201cscore\u201d an outfit is a creative problem that has no single answer! Here are a couple of score functions I wrote. They give outfits containing items that have high confidence matches more gravitas, and give a bonus to outfits that matched more items in my closet:<\/p>\n<div class=\"highlight\">\n<figure class=\"post-image post-mediaBleed alignnone\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1326895 lazy\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.08.21-PM.png\" alt width=\"758\" height=\"487\" sizes=\"(max-width: 758px) 100vw, 758px\" data-lazy=\"true\" data-srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.08.21-PM.png 758w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.08.21-PM-280x180.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.08.21-PM-420x270.png 420w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/11\/Screen-Shot-2020-11-05-at-1.08.21-PM-210x135.png 210w\"><\/figure>\n<\/div>\n<div readability=\"26.678651685393\">\n<p>If you want to see all this code together working in action, check out<span>&nbsp;<\/span><a href=\"https:\/\/github.com\/google\/making_with_ml\/blob\/master\/instafashion\/scripts\/getMatches.ipynb\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">this Jupyter notebook<\/a>.<\/p>\n<h2 id=\"putting-it-all-together\">Putting it all together<\/h2>\n<p>Once I had written all the logic for making outfits in a Python script, I ran the script and wrote all the results to Firestore. Firestore is a serverless database that\u2019s designed to be used easily in apps, so once I had all my outfit matches written there, it was easy to write a frontend around it that made everything look pretty. I decided to build a React web app, but you could just easily display this data in a Flutter or iOS or Android app!<\/p>\n<p>And that\u2019s pretty much it! Take that, expensive stylist.<\/p>\n<hr>\n<p><i><span>This <a href=\"https:\/\/daleonai.com\/social-media-fashion-ai\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">article<\/a> was written by <\/span><\/i><a href=\"https:\/\/daleonai.com\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><i><span>Dale Markowitz<\/span><\/i><\/a><i><span>, an Applied AI Engineer at Google based in Austin, Texas, where she works on applying machine learning to new fields and industries. She also likes solving her own life problems with AI, and talks about it on YouTube.<\/span><\/i><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"c-post-pubDate\"> Published November 7, 2020 \u2014 14:00 UTC <\/p>\n<p> <a href=\"https:\/\/thenextweb.com\/neural\/2020\/11\/07\/how-to-build-an-ai-stylist-inspired-by-outfits-on-instagram-syndication\/\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last year, in a universe where it still made sense to owns pants, I decided to hire a personal stylist. In our first appointment, the stylist came to my apartment and took&#8230;<\/p>\n","protected":false},"author":1,"featured_media":951,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.londonchiropracter.com\/index.php?rest_route=\/wp\/v2\/posts\/950"}],"collection":[{"href":"https:\/\/www.londonchiropracter.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.londonchiropracter.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.londonchiropracter.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.londonchiropracter.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=950"}],"version-history":[{"count":0,"href":"https:\/\/www.londonchiropracter.com\/index.php?rest_route=\/wp\/v2\/posts\/950\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.londonchiropracter.com\/index.php?rest_route=\/wp\/v2\/media\/951"}],"wp:attachment":[{"href":"https:\/\/www.londonchiropracter.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.londonchiropracter.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.londonchiropracter.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}