<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Olivier CHADENAT on Medium]]></title>
        <description><![CDATA[Stories by Olivier CHADENAT on Medium]]></description>
        <link>https://medium.com/@olivier-chadenat?source=rss-4b8304fba8b9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*GPLWEE7DyFRrPgT-wQT_kg.png</url>
            <title>Stories by Olivier CHADENAT on Medium</title>
            <link>https://medium.com/@olivier-chadenat?source=rss-4b8304fba8b9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 20:37:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@olivier-chadenat/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Product or Service Availability Tracker]]></title>
            <link>https://medium.com/thedevproject/product-or-service-availability-tracker-f9349697ab67?source=rss-4b8304fba8b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9349697ab67</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[tracker]]></category>
            <dc:creator><![CDATA[Olivier CHADENAT]]></dc:creator>
            <pubDate>Sat, 01 Jan 2022 17:23:51 GMT</pubDate>
            <atom:updated>2022-03-31T07:46:41.726Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to develop a custom product or service tracker in Python with minimal effort and cost?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N4mL6IjBJKxbxnRoAJVeuw.jpeg" /><figcaption>Image by the author</figcaption></figure><p>If you are a video games fan, or more recently an At-Home Covid Test hunter, you might know the famous <a href="http://www.nowinstock.net/">nowinstock.net</a> website that alerts you when a product is available for pre-order or to buy. However, sometimes, you need to be warned about the availability of a product or a service that will interest only you or a few people. In this case, mainstream websites such as <a href="http://nowinstock.net/">nowinstock.net</a> won’t be very helpful and you need to roll up your sleeves.</p><h3>Let’s take an example</h3><p>I needed to create a tracker to be alerted when kids&#39; ski lessons were available for reservation. For the school holidays, available spots are filled quickly and this is exacerbated by the current covid restrictions.</p><p>The ski station I am interested in has a webpage that will be updated when reservations are available. Therefore, the main task of the project is to write some Python code to scrape the page. Web scraping is the process of extracting data from websites.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*puzRmhp8HqeZ3q_zXJpwIA.jpeg" /><figcaption>Image by the author — Ski station webpage to be monitored</figcaption></figure><h3>Pre-requisites</h3><h4>Google Cloud Platform</h4><p>We will use <a href="https://cloud.google.com/">Google Cloud Platform (GCP)</a> to implement our tracker. I won’t cover how to create a Google Cloud Platform Account &amp; Project. It’s pretty straightforward to do it through the GCP Console and it’s well <a href="https://cloud.google.com/resource-manager/docs/creating-managing-projects#console">documented</a>.</p><h4>Email Delivery Service</h4><p>Once your product or service is available, you need to be alerted by text message, tweet, chat message, browser alert, or even a sound alert. For this example, we will keep it simple and universal by sending an email to alert the user(s). You will need to create an account for an API-based email delivery service such as <a href="https://www.mailgun.com/">Mailgun</a> or <a href="https://sendgrid.com/">SendGrid</a>. Both of these services are providing a free tier offer (i.e. it’s free if you stay below your email quota). I will describe the process of sending emails with Mailgun.</p><h3>Implementation</h3><h4>Web Scraping and Email Sending</h4><p>I strongly suggest writing and testing your code locally with Jupyter Notebook or your favorite IDE. You can not really debug your code in the Web Editor offered in the Google Cloud Console.</p><p>The web scraping code will check if the section mentioning that the reservation will be available soon changes. If it changes, I will consider that the ski lessons are open for reservation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fR09eLKbRm5MSBdScDU4Dw.jpeg" /><figcaption>Image by the author —our code will check if the text above is still present on the page</figcaption></figure><p>I am using the <a href="https://docs.python-requests.org/en/latest/">Requests Python library</a> to perform an HTTP request and retrieve the HTML code. Then, I am using the <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/">Beautiful Soup Python library</a> for extracting the section of interest (in this case, the text between the HTML &lt;h5&gt; tags that are within &lt;div&gt; tags with the CSS class “entry-content”).</p><p>Sending an email with Mailgun is as simple as doing an API call with the Requests Python library. API specifications are available <a href="https://documentation.mailgun.com/en/css-updates/api-sending.html#sending">here</a> and a quick user guide is also <a href="https://documentation.mailgun.com/en/latest/quickstart-sending.html#send-with-smtp-or-api">provided</a>. You will need to retrieve your Mailgun Private API key from the Mailgun Website (Settings/API Keys). The URL for the API call should have the following format: <a href="https://api.mailgun.net/v3/your-domain/messages.">https://api.mailgun.net/v3/<strong>your-domain</strong>/messages.</a> Adapt it with your domain name. The <strong>from </strong>parameter needs to be your Mailgun username.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FEUthneXmvRvuJtS33909w.jpeg" /><figcaption>Image by the author — retrieve the Mailgun Private API key</figcaption></figure><p>The code below is all the code you need to implement your custom tracker.</p><pre># Import Libraries<br>from bs4 import BeautifulSoup<br>import requests</pre><pre># Helper Function to send an email to alert the user/yourself<br>def send_alert():</pre><pre>    pwd = &quot;XXXXXX&quot;<br>    print(&quot;Page Changed&quot;)</pre><pre>    r = requests.post(<br>        &quot;https://api.mailgun.net/v3/your-domain/messages&quot;,<br>        auth=(&quot;api&quot;, pwd),<br>        data={&quot;from&quot;: &quot;XXXXXX&quot;,<br>        &quot;to&quot;: [&quot;your-email-address&quot;],<br>        &quot;subject&quot;: &quot;XXXXX Group Lesson Update&quot;,<br>        &quot;text&quot;: &quot;The Ski Group Lesson are now available&quot;})</pre><pre>    print(r.status_code )<br>    print(r.text)</pre><pre># Web Scrapping<br>original_text = &quot;Thank you for your interest in the XXXXX Snowsports programs – we are currently working on getting our packages on our online store for the 2021-22 season.  Please check back later to make reservations.&quot;</pre><pre>url = &quot;https://www.XXXXX.com/lesson/youth-group-lesson-packages/&quot;<br>r = requests.get(url)</pre><pre>if r.status_code == 200:<br>    try:<br>        soup = BeautifulSoup(r.content, &#39;html.parser&#39;)<br>        text_to_check = soup.find(&quot;div&quot;, class_=&quot;entry-content&quot;).find(&quot;h5&quot;).get_text().replace(u&#39;\xa0&#39;, u&#39; &#39;)</pre><pre>        if text_to_check != original_text:<br>             send_alert()<br>    except:<br>        send_alert()<br>else:<br>    print(&quot;Error&quot;, r.status_code)</pre><p>Once your code has been tested on your local environment, go to the <a href="https://console.cloud.google.com/home">GCP console</a>.</p><h4>Create a Google Cloud Function</h4><p>Google Cloud Function is the Google FaaS product. From <a href="https://en.wikipedia.org/wiki/Function_as_a_service">Wikipedia</a>:</p><blockquote>Function as a service (FaaS) is a category of cloud computing services that provides a platform allowing customers to develop, run, and manage application functionalities without the complexity of building and maintaining the infrastructure typically associated with developing and launching an app.</blockquote><p>Go to the console, search for Cloud Functions. Create a Function named <strong>ski-lessons-tracker</strong>. Choose Cloud Pub/Sub as a trigger for your function and create a Cloud Pub/Sub topic named <strong>ski-lessons-topic</strong>. You can use the default values for the other parameters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4wcsuSjzZ5lAQ-jQ0H4sbQ.jpeg" /><figcaption>Image by the author — Create a Cloud Function</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HEtS1t-qHCUwseRdU47DtA.jpeg" /><figcaption>Image by the author — Create a Pub/Sub Topic</figcaption></figure><p>Choose Python 3.7 for the runtime type and name your function entry point (e.g. <strong>ski_lessons_detector_pubsub</strong>). Click on requirements.txt and input the two python libraries needed for this project (Beautiful Soup and Requests) as per below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5e_Ay9SmRc9AsrEJCNn-wA.jpeg" /><figcaption>Image by the author — Requirements</figcaption></figure><p>Then, it’s time to copy-paste your code in the main.py file. You need to put the web scraping code in the function corresponding to the Entry Point previously defined.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wfuumPgSi4Kpz8IEObouhA.jpeg" /><figcaption>Image by the author — Cloud Function Code</figcaption></figure><p>Once the function has been successfully deployed, a Cloud Scheduler needs to be created to run the code at a pre-determined frequency.</p><h4>Setup the Cloud Scheduler</h4><p>Go to the console, search for Cloud Scheduler and create a new schedule. Give a name to your scheduler (e.g.<strong> ski-lessons-scheduler</strong>), a description, and set the time zone. The Frequency field is the one you should pay attention to. The syntax is based on Cron syntax. From <a href="https://en.wikipedia.org/wiki/Cron">Wikipedia</a>:</p><blockquote>The cron command-line utility, also known as cron job is a job scheduler on Unix-like operating systems.</blockquote><p><a href="https://cloud.google.com/scheduler/docs/configuring/cron-job-schedules?&amp;_ga=2.262119629.-1580276700.1637631695#defining_the_job_schedule">GCP documentation</a> is giving some examples of frequencies you can use. For this project, I want the code to run every 20 minutes. The Cron syntax is</p><p><strong>*/20 * * * *</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tn4VeLDmj11OqNr51TxLQA.jpeg" /><figcaption>Image by the author — Define the schedule</figcaption></figure><p><strong>Be careful when setting up the frequency. If your code runs too often, you might go over your quotas for GCP and Mailgun Free Tiers.</strong></p><p>In the next step, you will need to set the Target type to Pub/Sub and select the topic that was created previously. For this use case, the Message body field is not important so put whatever you want.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RgTsGrlwmGIjEdE13MtPoA.jpeg" /><figcaption>Image by the author</figcaption></figure><p>Once your scheduler job has been created, you can launch it to be sure it runs successfully.</p><h3>Waiting for the alert</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b6mdKQJkxfxgfjdG7wbo_Q.jpeg" /><figcaption>Image by the author — Email alert received when the webpage has been updated</figcaption></figure><h3>Additional Customizations</h3><p>There are many additional customizations you can implement. For instance, instead of copy-pasting your code from your local environment to GCP, you can <a href="https://cloud.google.com/source-repositories/docs/quickstart-integrating-with-cloud-functions">deploy to Cloud Functions from Cloud Source Repositories</a>.</p><p>Receiving alerts by email might not be the most efficient way to be alerted if your product or service is in high demand. Receiving a Text Message might be a better solution. You can look at services such as <a href="https://www.twilio.com/sms">Twilio</a> or <a href="https://simpletexting.com/">SimpleTexting</a> to automate sending SMS.</p><h3>Conclusion</h3><p>Once you are comfortable with web scrapping methods and Google Cloud Resources such as Function &amp; Scheduler, implementing a new tracker is very fast and usually depends on how difficult it is to web scrap a particular website.</p><p>Some of the technics shown in this article are useful for many automation use cases. I am using most of them for tasks related to <a href="https://www.footshirt.com/">FootShirt.com</a>, the website that I created a couple of years ago to cater to soccer jersey fans. Hopefully, this article can be a source of inspiration for some of your small or big projects.</p><p><em>Did you enjoy this article? Become a </em><a href="https://olivier-chadenat.medium.com/membership"><em>Medium member</em></a><em> to continue learning without limits. I’ll receive a portion of your membership fee if you use this </em><a href="https://olivier-chadenat.medium.com/membership"><em>link</em></a><em>, with no extra cost to you.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9349697ab67" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thedevproject/product-or-service-availability-tracker-f9349697ab67">Product or Service Availability Tracker</a> was originally published in <a href="https://medium.com/thedevproject">The Dev Project</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is it still worth it to build a Visual Search Engine from Scratch?]]></title>
            <link>https://medium.com/data-science/is-it-still-worth-it-to-build-a-visual-search-engine-from-scratch-65d9fc2f0b6b?source=rss-4b8304fba8b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/65d9fc2f0b6b</guid>
            <category><![CDATA[soccer]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[visual-search]]></category>
            <category><![CDATA[denoising-autoencoder]]></category>
            <category><![CDATA[google-vision-api]]></category>
            <dc:creator><![CDATA[Olivier CHADENAT]]></dc:creator>
            <pubDate>Sun, 30 May 2021 15:56:11 GMT</pubDate>
            <atom:updated>2021-10-25T14:52:10.237Z</atom:updated>
            <content:encoded><![CDATA[<h4>The long journey of developing a custom model cut short by Google Vision API Product Search</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lMEgTozXURyxLM5ODQmNTQ.jpeg" /><figcaption>Image by author</figcaption></figure><h3>Introduction</h3><p>I launched <a href="https://www.footshirt.com/">FootShirt.com</a> in 2018 with the ambition to create a platform for football (soccer) fans that enjoy collecting jerseys and/or are passionate about the history and values communicated by football shirts.</p><p><a href="https://www.footshirt.com/visual-search">FootShirt.com’s Visual Search Engine</a> is one of the most popular website features. This article will explain how I built the Visual Search Engine, starting with a custom Machine Learning model and then switching to <a href="https://cloud.google.com/vision/product-search/docs">Google Vision API Product Search</a>.</p><h3>What is a Visual Search Engine?</h3><p>A Visual Search Engine is a search engine designed to search for information through the input of an image. These search engines often use computer vision techniques to search for digital images in large databases (<a href="https://en.wikipedia.org/wiki/Content-based_image_retrieval">Content-Based Image Retrieva</a>l).</p><p>Two of the most famous Visual Search Engine (sometimes called Reverse Image Search) are <a href="https://tineye.com/">TinEye </a>and <a href="https://www.google.com/imghp">Google Images</a>. While these services are performing well to find similar pictures, they can not be used to efficiently identify football shirts because they do not have labels associated with the pictures.</p><h3>The long journey of developing a custom deep learning model</h3><h4>Problem Definition</h4><p>Identifying a jersey means finding out the team, season, and jersey type (Home/Away/Third, etc..). It’s pretty difficult for a human to identify a jersey because kit manufacturers (Nike, Adidas, Puma, etc..) need to create new jerseys every year while respecting the team colors &amp; identity. So the differences between jerseys can pretty small, especially if the kit sponsor stays the same.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*EYF8W2rs08t75tnFA0k4Pw.jpeg" /><figcaption>More difficult than identifying a dog vs a cat! (Image by author)</figcaption></figure><h4>Packshot vs User-Generated images</h4><p><a href="https://www.footshirt.com/visual-search">FootShirt.com’s Visual Search Engine</a> relies on a database of +7,000 reference images. Google offers a great explanation of what reference or packshot images are:</p><blockquote>Good reference images show the product clearly and do not have any other objects in the image. A typical example of good reference images are “packshot” images. These images are frequently used to show the user a product on the product page or in advertising, and typically taken in front of a white background.</blockquote><p>The Visual Search Engine will take a picture taken by the user or from the web as an input to identify jerseys. Therefore, it’s important to collect and label user-generated images (or <strong><em>noisy </em></strong>images) to include in the dataset used to train the model. It’s obviously a tedious process and many user-generated images are inadequate for model training, mainly for the following reasons:</p><ul><li>Busy background</li><li>Badly cropped picture</li><li>Other products in the image</li><li>Bad lighting</li></ul><h4>The model: Denoising Convolutional AutoEncoder</h4><p>Once I was done with building a dataset of almost 20,000 pictures, I started the model selection. Based on some research, I settled on implementing a Denoising Convolutional AutoEncoder. First, I highly recommend the following Medium article that addresses a similar problem: <a href="https://medium.com/@sorenlind/a-deep-convolutional-denoising-autoencoder-for-image-classification-26c777d3b88e">https://medium.com/@sorenlind/a-deep-convolutional-denoising-autoencoder-for-image-classification-26c777d3b88e</a></p><p>In a nutshell, the denoising convolutional AutoEncoder will extract important features to identify jerseys because the network will be trained to output what we give it as input. But we will do so by limiting the size of the layer in the middle (usually called latent space or bottleneck layer). This latent space represents the important features to identify jerseys and can be easily compared using libraries such as <a href="https://github.com/spotify/annoy">Annoy</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vo1zNesSEP0Zlc-svW-cmg.jpeg" /><figcaption>AutoEncoder (Illustration by author)</figcaption></figure><p>A regular AutoEncoder trained on the Reference images will not work for our use case because the Visual Search Engine needs to be able to work with User-Generated images. Therefore, User-Generated images will also be used in the training (thus the <strong><em>Denoising </em></strong>in Denoising Convolutional AutoEncoder).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/0*aHcpqSVQbH3DG__m" /><figcaption>Left: the User-Generated image (“noisy”), Center: the Reference image, Right: the image reconstructed by the AuotEncoder (Illustration by author)</figcaption></figure><p>I am not going to go too much into the details but here are some of the issues I encountered during the training:</p><ul><li>Model accuracy was dropping fast with picture resolution. As mentioned before, there might be very few differences between jerseys, and details matter. I settled on a 256 x 256 resolution.</li><li>The model required many layers to perform well.</li><li>Accuracy started to be acceptable (+70%) only after training the model for 400 epochs.</li></ul><p>Therefore, the training time became an issue as the model needed to be trained for many hours or even several days (using GPU on Google Colab or Nvidia Tesla V100/P100 on Google Cloud Platform).</p><p>However, I was able to reduce the training time dramatically when I converted the images in the dataset to <a href="https://www.tensorflow.org/tutorials/load_data/tfrecord">TFRecords</a> and started using TPU on <a href="https://colab.research.google.com/">Google Colab</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*zYYAaOn6uBCCsyPjd6ux3w.png" /><figcaption>Training Loss is going down (Illustration by author)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I10A3oOUbs_JiwTjlUxgjw.jpeg" /><figcaption>The more epochs used for training, the better the reconstructed image is (Illustration by author)</figcaption></figure><h4>The results in the Real World</h4><p>After deploying the model using Flask, it was time to see how the Visual Search Engine was behaving in the real world. Overall, the results were good …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*50HPfXo_d9H-CdDT5rQOEw.jpeg" /><figcaption>Yeah, it works! The Search Engine correctly identified the Juventus 2005–2006 Home kit (Illustration by author)</figcaption></figure><p>but not <strong>very </strong>good as shown in the example below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q334oEBJid90ePRtPfTDfQ.png" /><figcaption>The model placed too much emphasis on the overall shape (long sleeve) of the jersey (Illustration by author)</figcaption></figure><p>The model accuracy was not good enough (in the low 70%) and the Visual Search Engine maintenance was also problematic as new reference jerseys needed to be encoded and a new Annoy Index needed to be built.</p><h3>Here comes Google Vision API Product Search</h3><p>Can <a href="https://cloud.google.com/vision/product-search/docs">Google Vision API Product Search</a> perform well for Soccer Shirts? My main concern using a product such as <a href="https://cloud.google.com/vision/product-search/docs">Google Vision API Product Search</a> was the inability of the underlying model to generalize, making it unfit to correctly identify Soccer Jerseys. Can I get better accuracy without going through Hyper Parameters tuning, VM provisioning, retraining, etc..?</p><p>I am not going into too much detail on how to use Google Vision API Product Search, the documentation provided by Google is excellent. However, I will explain the main steps required to quickly roll out a Visual Search Engine. Developing a custom model was everything except a waste of time. Many of the application blocks such as image processing, model evaluation, Flask API were already done. This is the main reason why rolling out a Visual Search Engine based on <a href="https://cloud.google.com/vision/product-search/docs">Google Vision API Product Search</a> for <a href="https://www.footshirt.com/">FootShirt.com</a> was a matter of hours.</p><h4>Formatting a bulk import CSV and uploading the pictures to a Google Cloud Storage bucket.</h4><p>The easiest way to get started is to prepare a CSV file for bulk import following <a href="https://cloud.google.com/vision/product-search/docs/csv-format">the guidelines provided in the documentation</a>. The CSV file will be used to create a product set and products with reference images, all at the same time. Leveraging the FootShirt.com database and some Python code, it was pretty easy to create the CSV file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aC7K-0Egy6obZaELlszNYQ.jpeg" /><figcaption>Extract of the CSV file used for the bulk import (Image by author)</figcaption></figure><p>Then, you need to store the images <strong>AND </strong>the CSV file in a Google Cloud Storage Bucket.</p><h4>Creating a product set, create multiple products and their reference images</h4><p>Using the <a href="https://cloud.google.com/vision/product-search/docs/create-product-set">Python Code example</a> provided by Google and the CSV file created previously, you can use bulk import to create a product set with products. It might take between 5 and 30 minutes depending on the number of images you have.</p><h4>It’s time to test!</h4><p>Once again, Google is providing excellent <a href="https://cloud.google.com/vision/product-search/docs/searching">code examples</a> to search for products or in our case to identify a soccer jersey.</p><p>By using <a href="https://cloud.google.com/vision/product-search/docs">Google Vision API Product Search</a>, <a href="https://www.footshirt.com/visual-search">FootShirt.com’s Visual Search Engine</a> is now performing better (accuracy of around 90%). One of my favorite features is the score or confidence level returned by the API (in parenthesis, in the screenshots below). This allows setting a threshold below which you will let your users know that no result was found.</p><p>Google Vision API Product Search seems to rely a lot on text recognition, or in the context of soccer jersey identification, on the sponsor’s name. The example below shows that the sponsor’s name has more importance than the jersey color (the second hit is a white jersey while the input was a black jersey but the sponsor is identical !)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J2Ig9WoEuhUlmgBS3B2q1A.jpeg" /><figcaption>This time, the Visual search Engine does not get tricked by the long sleeves (Illustration by author)</figcaption></figure><p>I confirmed my intuition by providing as input, the picture of a jersey with no sponsor while I knew the Reference Image had the sponsor&#39;s name. <a href="https://cloud.google.com/vision/product-search/docs">Google Vision API Product Search</a> had more difficulties finding the right match (AC Milan 2018–2019 Home kit), returning as 1st and 2nd choice similar jerseys with no Sponsor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TG9jlN_6tNbBgFkQOWf7dg.jpeg" /><figcaption>Still not perfect but close — Confidence level between the first 3 hits is respectively 0.62, 0.61, 0.58 (Illustration by author)</figcaption></figure><h4>Costs</h4><p>A word about <a href="https://cloud.google.com/vision/product-search/pricing">cost</a>. You are charged for the storage of images and the number of API calls.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WA6NsfnoqtAuiXWg3PCf3g.jpeg" /><figcaption>Google Vision API Product Search — Pricing (illustration by author)</figcaption></figure><p>For a website such as <a href="https://www.footshirt.com/">FootShirt.com</a>, with tens of thousands of pictures, the storage cost and the prediction cost are reasonable (less than $10 per month for a Visual Search Engine!).</p><h3>Conclusion</h3><p><a href="https://www.footshirt.com/visual-search">FootShirt.com’s Visual Search Engine</a> can be used to help you build a digital collection on <a href="https://www.footshirt.com/">FootShirt.com</a> by providing pictures of your jerseys. But the Search Engine can also be used to identify a jersey before buying or selling a jersey on eBay or to identify a soccer shirt you found on the web or on social media.</p><p><a href="https://cloud.google.com/vision/product-search/docs">Google Vision API Product Search</a> hit all my requirements for a Visual Search Engine to identify soccer jerseys: easy to interface with, fast prediction, and low cost.</p><p>I encourage you to test <a href="https://www.footshirt.com/visual-search">FootShirt.com’s Visual Search Engine</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vnPOcYeDyGl5ppNsZQoyHg.jpeg" /><figcaption><a href="https://www.footshirt.com/visual-search">FootShirt.com’s Visual Search Engine</a> in action (Illustration by author)</figcaption></figure><p>On a different note, I am not done experiencing with Machine Learning models to identify soccer jerseys. My next project is likely to be Real-Time Inference using the new <a href="https://store.opencv.ai/products/oak-1">OAK-1</a>. Stay tuned and do not hesitate to post your comments!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Xi2xHIKHNCmxRavkxXvxCg.jpeg" /><figcaption>OAK-1: 4K camera for real-time Inference (Image by author)</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65d9fc2f0b6b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/is-it-still-worth-it-to-build-a-visual-search-engine-from-scratch-65d9fc2f0b6b">Is it still worth it to build a Visual Search Engine from Scratch?</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Science and Soccer Shirts — Part 1]]></title>
            <link>https://medium.com/swlh/data-science-and-soccer-shirts-part-1-c9e95e06788?source=rss-4b8304fba8b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9e95e06788</guid>
            <category><![CDATA[scatter-plots]]></category>
            <category><![CDATA[plotly]]></category>
            <category><![CDATA[matplotlib]]></category>
            <category><![CDATA[data-visualisation]]></category>
            <category><![CDATA[soccer]]></category>
            <dc:creator><![CDATA[Olivier CHADENAT]]></dc:creator>
            <pubDate>Sun, 17 Nov 2019 01:52:10 GMT</pubDate>
            <atom:updated>2019-11-28T00:23:32.928Z</atom:updated>
            <content:encoded><![CDATA[<h3>Data Science and Soccer Shirts — Part 1</h3><p>This article is the first one of a series about Data Visualization and Machine Learning using a soccer jerseys dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*KfZyVsrQV1qkzbqLPHgU5Q.jpeg" /></figure><h3>Introduction</h3><p>The goal of this series of articles is to demonstrate the use of data visualization and machine learning techniques while hopefully using a fun dataset. Part 1 will focus on soccer shirts’ dominant color and 3D Scatter Plots. First, we will use the <a href="https://matplotlib.org/">Matplotlib </a>library, and then we will explore the additional functionalities that <a href="https://plot.ly/">Plotly</a> offers.</p><p>You can find a Git Repository with a Jupyter notebook <a href="https://github.com/ochadenat/soccer_jerseys_color_analysis">here</a>.</p><h3>Dataset</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*O8SCrEiaFlExSxciJNcsLg.png" /></figure><p><a href="https://www.footshirt.com/">FootShirt.com</a> is the site for soccer fans that enjoy collecting jerseys and are passionate about the history and values communicated by soccer shirts.</p><p><em>Disclaimer: I am also the founder of FootShirt.com</em></p><h4>Home, Away and Third Jerseys</h4><p>For a very long time, soccer teams had only two jerseys referenced as Home and Away. These two jersey types had very distinct colors in case two squads having the same primary color were playing against each other (think Manchester United versus Liverpool Red Jerseys). It’s worth mentioning that many teams have still an Away jersey with white as the dominant color, likely a heritage from the black and white TV era.</p><p>Third Jerseys started appearing 20 years ago. Squads are using them if both their first-choice and away colors are deemed too similar to those of an opponent. It’s also believed to be a way for kit suppliers to increase sales by offering designs that appeal to younger generations (bright colors, etc…). Recently, Clubs have been using their Third Jerseys for the Away games in the European Cups (UEFA Champions League and Europa League).</p><h4>Records</h4><p>The dataset has around 3,200 records (i.e., jerseys) covering 156 teams (104 Clubs and 52 National squads). Some teams might have only one jersey in the dataset, while clubs with many fans such as Manchester United will have 104 jerseys. Also, the recent period is more represented compared to other periods: 2,034 jerseys for 2005–2019 vs. 1,198 jerseys for the period pre-2005.<br>Consequently, this dataset is introducing a bias toward famous teams and the recent past. Besides, most analyses and visualizations are excluding Goalkeeper jerseys.</p><h4>Fields Description</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*jfQKcl5WaB82fINMAFwBkA.jpeg" /><figcaption>Fields Description</figcaption></figure><p>Each jersey is assigned <strong>one (and only one) dominant color</strong>. We will use the RGB color model in which each parameter (Red, Green, and Blue) defines the intensity of the color as an integer between 0 and 255.</p><p>A future dataset will provide the ability to show several dominant colors to take into account shirts such as Juventus Turin Home jerseys, where both black and white can be considered as dominant colors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZoSjoecf8S3lPSbJD_M6PQ.png" /><figcaption>Future Dataset: Juventus Turin will have two dominant colors, black &amp; white</figcaption></figure><h3>Data Visualization with Matplotlib</h3><h4>Matplotlib 3D scatter plot</h4><p>Python offers many visualization libraries (<a href="https://matplotlib.org/">Matplotlib</a>, <a href="https://seaborn.pydata.org/">Seaborn</a>, <a href="https://plot.ly/">Plotly</a>, <a href="https://bokeh.pydata.org/en/latest/">Bokeh</a>, etc..). Matplotlib is my favorite choice for 3D scatter plot. The snippet below shows how I like to import and configure Matplotlib for 3D scatter plot.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/08bb2614f07abac1870b12ea45117808/href">https://medium.com/media/08bb2614f07abac1870b12ea45117808/href</a></iframe><h4>Visualizing the entire dataset</h4><p>Our first task is to display soccer shirts’ dominant color for the whole dataset. The RGB color model can be represented in a three-dimensional coordinate system: the horizontal x-axis for red, y-axis for green, and the vertical z-axis for blue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*BrpnY5IamzMh3TlOmNOwIw.png" /><figcaption>Soccer Shirts’ Dominant Colors (sample size: 3,229)</figcaption></figure><p>For anyone familiar with Matplotlib, creating a 3D scatter plot is pretty easy. The only difference is the <em>projection </em>parameter that needs to be set to “3d” when adding your chart.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cbca10b57a24d11455141ecaa4d4e9b0/href">https://medium.com/media/cbca10b57a24d11455141ecaa4d4e9b0/href</a></iframe><p>The mapping of each RGB component to the three axes is important. Our first chart seems to show that very few jerseys have green as a dominant color. However, mapping green to the x-axis and red to the y-axis is telling another story. Please keep reading this article as I will explain how Plotly can be used to mitigate this issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*jQLEo9ierSCMUYv13mbd9A.png" /><figcaption>Same data but we switched axis for the Green and Red component</figcaption></figure><h4>Soccer Shirts’ Dominant Colors for the 2018 Fifa World Cup</h4><p>The 2018 Fifa World Cup Russia was featuring 32 teams, and each team had a Home Jersey and an Away Jersey (so the dataset has 64 jerseys, each having a dominant color). The three charts below show the color distribution, respectively, for all jerseys, Home jerseys, and Away jerseys.</p><p>Red and White are the most frequent colors for Home shirts, while White is by far the most frequent color for Away jerseys.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*yHoYpB89BLuhZZSDiSJZig.png" /><figcaption>Soccer Shirts’ Dominant Colors for the 2018 Fifa World Cup</figcaption></figure><p>To better visualize points laying over each other, I like to add a thin black border with the <em>linewidths </em>and <em>edgecolors </em>parameters</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e6e0cab55fd5e106e1454c16b00e6d5/href">https://medium.com/media/3e6e0cab55fd5e106e1454c16b00e6d5/href</a></iframe><h3>Focus on Liverpool</h3><p>The same approach can be used to focus on a specific squad. Liverpool is the 2019 UEFA Champions League Winner and has a high diversity of dominant colors for their Away and Third kits (perhaps due to the fact they switched kit supplier many times in the past 15 years — New Balance, Warrior Sports, Adidas, Reebok)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*dVSBOYqEZrRuBfbAg-N6jg.png" /><figcaption>The dominant color for Liverpool Jerseys (sample size: 72)</figcaption></figure><h3>Is Manchester United red identical to Liverpool red?</h3><p>A discussion on France’s most popular soccer radio show (RMC After Foot) inspired the following analysis. Two journalists could not agree on which team red was brighter. Some websites (e.g., <a href="https://teamcolorcodes.com/">teamcolorcodes.com</a>, <a href="https://www.schemecolor.com/">schemecolor.com</a>) are listing the clubs’ official colors, mostly based on club crests, but when it comes to Manchester United and Liverpool jerseys, it’s difficult to conclude.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*GEWj1JLBwMDw4JyeSvUf5w.png" /><figcaption>Comparison between two teams</figcaption></figure><p>The chart above is using a couple of techniques to improve readability. First, I am using a different marker for each team (circle for Manchester United, diamond for Liverpool). Second, I am using a trick to display the legend correctly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/002066f7d754c30898e73f291a3502fc/href">https://medium.com/media/002066f7d754c30898e73f291a3502fc/href</a></iframe><h3>Data visualization with an HTML Table</h3><p>The following technique is one of my favorites to quickly and efficiently compare colors. It consists of displaying an HTML table and use the colors you want to compare as a background color for the cells.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f58276250fee514fdde2278cca2a3ef3/href">https://medium.com/media/f58276250fee514fdde2278cca2a3ef3/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*3sp6tu46r62oZHRDv7_k5w.jpeg" /><figcaption>Red Shades for Liverpool Home Jerseys (from 2011 to 2019)</figcaption></figure><h3>Data Visualization with Plotly</h3><h4>Matplotlib Shortcomings</h4><p>While Matplotlib is a great library to have a peek at your data, the lack of interactivity might sometimes be an issue. The ability to rotate along the axis and the presence of an infotip to display additional information are two important functionalities.</p><h4>Getting Started with Plotly</h4><p>To get started with Plotly, create a free account, get your API Key, and follow the instruction on <a href="https://plot.ly/python/getting-started/">Plotly Getting Started page</a>.</p><h4>Your first 3D Scatter Plot with Plotly</h4><p>The code below has been adapted from the Plotly tutorial. With very few lines of code, we can to generate a 3D scatter plot that is visually very appealing and provide great functionalities to the users (ability to rotate, tooltip, etc…)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9b1c87e38a64bcd6f0bb980c3f0568ee/href">https://medium.com/media/9b1c87e38a64bcd6f0bb980c3f0568ee/href</a></iframe><p>I am using the infotip functionality to quickly identify outliers such as this bright pink Real Madrid Away jersey!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b0D6SlohDsVa5jEgJWA4kg.png" /><figcaption>Plotly — Using the tooltip to identify an outlier — Jersey picture from Footshirt.com</figcaption></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FdyrKv95ztXA%3Ffeature%3Doembed&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DdyrKv95ztXA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FdyrKv95ztXA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0b59482a4faf42bc258830cb7732a03/href">https://medium.com/media/e0b59482a4faf42bc258830cb7732a03/href</a></iframe><h3>Conclusion</h3><p>I hope you enjoy this article about data visualization using soccer jerseys’ dominant color. Matplotlib and Plotly are two great tools to create 3D Scatter Plots. If you are interested in running your own analysis, you can contact me, and I will be happy to share the dataset.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9e95e06788" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/data-science-and-soccer-shirts-part-1-c9e95e06788">Data Science and Soccer Shirts — Part 1</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>