<?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 Thomas Nguyen on Medium]]></title>
        <description><![CDATA[Stories by Thomas Nguyen on Medium]]></description>
        <link>https://medium.com/@thomas.ngn?source=rss-823cda6b406c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*rIT58IgQrfsfcmxdoNkfdQ.png</url>
            <title>Stories by Thomas Nguyen on Medium</title>
            <link>https://medium.com/@thomas.ngn?source=rss-823cda6b406c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 02:08:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thomas.ngn/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[Creating a Computer Vision API in 60 minutes]]></title>
            <link>https://medium.com/dain-studios/creating-a-computer-vision-api-in-60-minutes-658ff64ae4f7?source=rss-823cda6b406c------2</link>
            <guid isPermaLink="false">https://medium.com/p/658ff64ae4f7</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Thomas Nguyen]]></dc:creator>
            <pubDate>Wed, 04 Sep 2019 07:56:36 GMT</pubDate>
            <atom:updated>2019-10-14T12:59:09.833Z</atom:updated>
            <content:encoded><![CDATA[<p>How to create a Computer Vision API in 60 minutes using fast.ai library, Flask, and Google Colab?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qzb7m_JTZd5bungsao7PKg.jpeg" /></figure><h3>Requirements</h3><p>The requirements are straightforward. You need a Google account in order to able to access your <a href="https://drive.google.com/">Google Drive</a> and use <a href="https://colab.research.google.com/">Google Colab</a>.</p><h3>1. Create your Image Dataset</h3><p>We are going to classify flowers but, instead of taking existing datasets available from the Internet, we are going to build our own labeled image dataset using Google Images.</p><p>First, open your new notebook Google Colab and connect it to your drive with the following code:</p><pre>from google.colab import drive<br>drive.flush_and_unmount()<br>drive.mount(&#39;/content/gdrive&#39;, force_remount=True)<br>root_dir = &quot;/content/gdrive/My Drive/&quot;</pre><p>You will be asked to click a link and copy/past the code that will be given to you in the box appearing in the output of the cell.</p><p>Now you can access the data in your Drive from your notebook.</p><p>Download the images and store them into your Drive. To do this, go on Google Image and search for the objects you want to classify. In our case, we want to classify Sunflower, yellow Daisy and yellow Tulip. Let’s start with the Sunflowers. Search Sunflowers on Google image and scroll to the bottom until you see <em>show more results</em>. Then, open the developer mode of your browser and go the Web Console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZD3eedCTaJU1km6dfnEb0Q.png" /></figure><p>There, past the following code to download a CSV of all the image urls:</p><pre>urls = Array.from(document.querySelectorAll(&#39;.rg_di .rg_meta&#39;)).map(el=&gt;JSON.parse(el.textContent).ou);<br>window.open(&#39;data:text/csv;charset=utf-8,&#39; + escape(urls.join(&#39;\n&#39;)));</pre><p>This triggers the download of the file. Save it and upload it using the widget on the left of the Notebook: Files &gt; Upload. Do the same for the other flowers.</p><p>We are going to now use the <a href="http://fast.ai/"><em>fast.ai</em></a><em> </em>library. Create a cell and paste:</p><pre>!curl -s https://course.fast.ai/setup/colab | bash</pre><p>This will install the library and configure your Colab notebook to run smoothly with it. Then, activate the GPU going to <em>Runtime &gt; Change Runtime Type &gt; GPU.</em></p><p>Now, import the library and download the images:</p><pre>from fastai.vision import *<br>from fastai.metrics import error_rate</pre><pre>folders_files = [(&#39;sunflowers&#39;, &#39;sunflowers.csv&#39;), (&#39;yellow_daisy&#39;, &#39;yellow_daisy.csv&#39;), (&#39;yellow_tulips&#39;, &#39;yellow_tulips.csv&#39;)]<br>for (folder, file) in folders_files:<br>  path = Path(root_dir + &#39;DeepLearning/Datasets/&#39;)<br>  folder = (path/folder)<br>  folder.mkdir(parents=True, exist_ok=True)<br>  download_images(path/file, folder, max_pics=200)<br>  verify_images(folder, delete=True, max_size=500)</pre><p>Here we create a folder and download 200 images for each class and verify they are not corrupted.</p><p>Next, we create an <em>ImageDataBunch</em> from the downloaded images. This object will represent our data with their labels. To optimise the process, we also:</p><ul><li>Split the data to have 20% of validation</li><li>Resize the data in squares of 224 pics</li><li>Operate image augmentation with <em>get_transforms</em></li><li>Normalize the data</li></ul><pre>np.random.seed(42)<br>data = ImageDataBunch.from_folder(path, train=&quot;.&quot;, valid_pct=0.2,<br>        ds_tfms=get_transforms(), size=224, num_workers=4).normalize(imagenet_stats)</pre><p>Let’s visualize our data:</p><pre>data.show_batch(rows=3, figsize=(7,6))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*v7f1GG5SzlJCPzossFGOww.png" /></figure><p>Everything seems correct. However to ensure optimal performance, you should check the images manually and remove the non-consistent images from your dataset. The Google Drive UI is quite convenient for validating and filtering images manually.</p><p>Now we are going to train our model. The <a href="http://fast.ai/">fast.ai</a> library is very concise and is set with good default features.</p><pre>learn = cnn_learner(data, models.resnet34, metrics=error_rate)<br>learn.fit_one_cycle(4)</pre><p>With these lines, we are downloading a pre-trained model ResNet34, passing our data and setting the metric as the error rate.</p><p>Then, we fit the model with the one cycle policy, as this mode of approach usually performs well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*8_pc3iU8BLIwmY8da4B9OA.png" /></figure><p>We get an error rate of 6% which is not bad, but we could do better. We were training the top layers of the pre-trained model. Let’s unfreeze all layers so their parameters are able to be modified during the training phase.</p><p><a href="http://fast.ai/">fast.ai</a> library provides <em>lr_find </em>which will launch an LR range test that will help you select a good learning rate. Plotting the curve:</p><pre>learn.unfreeze()<br>learn.lr_find()<br>learn.recorder.plot()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*m8rIV2A5M4RNN1PH1VGOvQ.png" /></figure><p>A rule thumb is to spot the strongest downward slope. Therefore we pick the beginning of the range at 1e-5 and choose to stop at 1e-4 because we were already training at 1e-3 by default. That way, the first layers are will be trained with a learning rate of 3e-5 and the last ones at 3e-4.</p><pre>learn.fit_one_cycle(10, max_lr=slice(3e-5,3e-4))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*Cgulh_hWXVUaH7e0nN6M7w.png" /></figure><p>3.5% of error, which is better.</p><p>Let’s analyze the classification errors:</p><pre>interp = ClassificationInterpretation.from_learner(learn)<br>interp.plot_confusion_matrix(figsize=(12,12), dpi=60)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*MolWc2k_plhK1EgZ5ss1RA.png" /></figure><p>We see most of the errors come from the confusion between yellow daisy and sunflowers which can be understandable due to their visual similarities. Plotting the errors which had the biggest top loss can help us to further understand the causes of the error.</p><pre>interp.plot_top_losses(9, figsize=(15,11))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*6mzHbhNvGpOWBQWT_-OEMg.png" /></figure><p>Some normal images have been misclassified, but others don’t look like flowers at all. This process demonstrates that we have not cleaned the dataset to the extent that we should have. Therefore, to improve performance, we should clean the image dataset and rerun the process to have a consistent score.</p><p>After cleaning and retraining our model, it should be a shame to keep it in the notebook, let’s put it now in production!</p><p>Save your model:</p><pre>learn.export()</pre><p>Download it and save it at the base of your API local folder. We are going now to build a basic API which will allow the user to upload an image and get the prediction.</p><p>Create a virtual environment with Python 3 having Flask and <a href="http://fast.ai/">fast.ai</a> library.</p><p>Create api_endpoint.py and past the following code:</p><pre>import os<br>from flask import Flask, flash, request, redirect, url_for, send_from_directory, jsonify<br>from werkzeug.utils import secure_filename<br>from fastai.vision import *<br></pre><pre>app = Flask(__name__)</pre><pre>UPLOAD_FOLDER = os.getcwd() + &#39;/files/&#39;<br>ALLOWED_EXTENSIONS = {&#39;png&#39;, &#39;jpg&#39;, &#39;jpeg&#39;, &#39;gif&#39;}</pre><pre>app = Flask(__name__)<br>app.config[&#39;UPLOAD_FOLDER&#39;] = UPLOAD_FOLDER<br></pre><pre>def allowed_file(filename):<br>    return &#39;.&#39; in filename and \<br>           filename.rsplit(&#39;.&#39;, 1)[1].lower() in ALLOWED_EXTENSIONS</pre><pre>@app.route(&#39;/&#39;, methods=[&#39;GET&#39;, &#39;POST&#39;])<br>def upload_file():<br>    if request.method == &#39;POST&#39;:<br>        # check if the post request has the file part<br>        if &#39;file&#39; not in request.files:<br>            flash(&#39;No file part&#39;)<br>            return redirect(request.url)<br>        file = request.files[&#39;file&#39;]<br>        # if user does not select file, browser also<br>        # submit an empty part without filename<br>        if file.filename == &#39;&#39;:<br>            flash(&#39;No selected file&#39;)<br>            return redirect(request.url)<br>        if file and allowed_file(file.filename):<br>            filename = secure_filename(file.filename)<br>            img = open_image(file)<br>            pred, _, losses = learner.predict(img)<br>            print(pred)<br>            file.save(os.path.join(app.config[&#39;UPLOAD_FOLDER&#39;], filename))<br>            return jsonify(str(pred))<br>    return &#39;&#39;&#39;<br>    &lt;!doctype html&gt;<br>    &lt;title&gt;Upload new File&lt;/title&gt;<br>    &lt;h1&gt;Upload new File&lt;/h1&gt;<br>    &lt;form method=post enctype=multipart/form-data&gt;<br>      &lt;input type=file name=file&gt;<br>      &lt;input type=submit value=Upload&gt;<br>    &lt;/form&gt;<br>    &#39;&#39;&#39;</pre><pre>@app.route(&#39;/uploads/&lt;filename&gt;&#39;)<br>def uploaded_file(filename):<br>    # return send_from_directory(app.config[&#39;UPLOAD_FOLDER&#39;],<br>    #                            filename)<br>    return &#39;File updated!&#39;</pre><pre>if __name__ == &#39;__main__&#39;:<br>    defaults.device = torch.device(&#39;cpu&#39;)<br>    learner = load_learner(&#39;.&#39;)<br>    print(&#39;OK&#39;)<br>    app.run(host=&quot;0.0.0.0&quot;, port=int(&quot;80&quot;), debug=True)</pre><p>We load our model line 58.</p><p>Launch your API with python api_endpoint.py and access with <a href="http://0.0.0.0/">http://0.0.0.0/</a></p><p>There you can upload your image and get your classification. For example with this image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*GW057v_YwY_VSyyWcUHfiw.png" /></figure><p>You get a JSON response:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*sDYtZmB7dbtyDgSZGCy8Ow.png" /></figure><p>To go deeper into this topic, I highly recommend you try the excellent courses of <a href="https://www.fast.ai/">https://www.fast.ai/</a>.</p><p><a href="https://github.com/dainstudios/api-flower-classifier">You can also find the code in the repository</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=658ff64ae4f7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dain-studios/creating-a-computer-vision-api-in-60-minutes-658ff64ae4f7">Creating a Computer Vision API in 60 minutes</a> was originally published in <a href="https://medium.com/dain-studios">DAIN Studios</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring the Data Realm: Running a Data Audit]]></title>
            <link>https://medium.com/dain-studios/exploring-the-data-realm-running-a-data-audit-52fc1d4e2d6e?source=rss-823cda6b406c------2</link>
            <guid isPermaLink="false">https://medium.com/p/52fc1d4e2d6e</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[data-management]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[digital-transformation]]></category>
            <dc:creator><![CDATA[Thomas Nguyen]]></dc:creator>
            <pubDate>Tue, 13 Aug 2019 11:36:17 GMT</pubDate>
            <atom:updated>2019-08-13T11:36:17.056Z</atom:updated>
            <content:encoded><![CDATA[<p>Many companies want to embrace digital transformation and use Artificial Intelligence (AI). They have the ideas, resources, and a vision, but the foundations are missing. That is, a deep knowledge of their data, from how they use and define terminologies, to how they store, use and archive data. <strong>Most AI and data analytics use cases will require connecting multiple and different data sources and types to gain deep insights and business optimization outcomes. However, a lack of knowledge and narrow vision of the data ecosystem can be a threat to the success of these projects.</strong></p><p>This post aims to give an overview of the <strong>Principles of the Data Audit</strong> which will be the first milestone for sustainable <strong>Data Management.</strong></p><h3>Principles</h3><p>The Data Audit is composed of 3 main iterative steps: the data asset identification, the measurement/evaluation of the data quality and the enrichment of the data through better quality processes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7VjBdZUs1nqip7GjYnxFcg.png" /></figure><h3>Identify the data assets</h3><p>First things first, get familiar with the data ecosystem. There are data and it can be described in many different ways. The characteristics of the data asset need prudence in definition to be fully understood. It is important to ask questions such as:</p><p>How to identify a data asset? What is the right level of detail?</p><p>To identify a data asset in the most efficient way, it is necessary to know its life cycle.</p><p>First, let’s define a <strong>data asset</strong>.</p><blockquote><strong>Any entity that is comprised of data. A data asset may be a system or application output file, database, document, or Web page, also a service that may be provided to access data from an application.</strong></blockquote><p><em>National Institute of Standards and Technology — U.S. Department of Commerce</em></p><ol><li><strong>Planning</strong>: Identify objectives, plan information architecture, develop standards and definitions;</li><li><strong>Obtainment</strong>: Ways to acquire data. For example, by creating records, purchasing data, or loading external files;</li><li><strong>Storage and Sharing</strong>: Form of storing and sharing data. Data may be stored electronically such as in databases or files. Data can be shared through such means as networks, emails or APIs;</li><li><strong>Maintenance</strong>: Update, change, and manipulate data. Cleanse, wrangle and transform data. Match and merge records, or optimize data;</li><li><strong>Use</strong>: Retrieve data. Use information. Use can be completing a transaction, writing a report, making a management decision from a report, and/or running automated processes;</li><li><strong>Disposal</strong>: Archive information or deleting data or records;</li></ol><p>For each phase, <strong>four aspects have to be taken in account</strong>:</p><ul><li>the <strong>What: </strong>what data is concerned during these phases?.</li><li>the <strong>How</strong> — <strong>Processes: </strong>how are these phases executed from a procedural point of view?</li><li>the <strong>Who</strong>: who is involved in these phases?</li><li>the <strong>How — Technology</strong>: how are these phases executed from a technological point of view?</li></ul><p>This framework gives a holistic view of the analyzed data assets: <strong>it will be the pedestal for improving the data asset, imagining new use cases and making data governance implementable.</strong></p><h3>Measure and Evaluate Data Quality</h3><p>Now that the data asset can be identified, the next step is to determine if the data is usable? Not all data is usable or relevant to the AI and analytics use cases, and therefore it is important and necessary to assess data quality. To do this, we ask the following questions:</p><p>What makes data quality? Is it necessary to have an impeccable data asset?</p><p>Data quality relies on <strong>metrics</strong> that will be confined to <strong>business rules</strong>. These metrics will be the same for all data assets but it will not be the case for the business rules. The comparison of the two will give the <strong>validation of the data quality</strong>.</p><h3>Data Quality Metrics</h3><p>Data quality can be measured with 6 main metrics:</p><ul><li><strong>Timeliness: </strong>Describe the latency between the event and the availability of the information — e.g. the contracts data set is refreshed once per year;</li><li><strong>Completeness</strong>: Percentage of values that are considered as complete — e.g. only 80% of the timestamps are complete;</li><li><strong>Validity</strong>: Respect of a certain syntax, range or set of rules — e.g. age has to be between 18 and 110 for some cases;</li><li><strong>Uniqueness</strong>: Presence of duplicates or missing values — e.g. if a business serves 100 clients, there shouldn’t be more than 100 in the data set;</li><li><strong>Consistency</strong>: Consistency in the way to represent data — e.g. dates are always encoded in the same way;</li><li><strong>Accuracy</strong>: Exactitude of the data in comparison with the reality — e.g. the billing system should be the same, and consistent with, the financial data sets.</li></ul><p>At the exception of timeliness, all the other metrics are measured at the level of fields.</p><h3>Business Rules</h3><p>It’s good to be able to quantify the data quality but <strong>the final goal is to qualify data reliability</strong>. Indeed, <strong>not all the fields of a data set have the same importance</strong>: inaccuracy, incompleteness, and non-validity can be accepted for some of them.</p><p>To qualify this data reliability, one first step is to define business-related data quality rules. These rules are defined by the owner of the data asset and they represent the standard from which data can be qualified as reliable. Each metric we’ve seen previously should have its own business rule but it can happen in cases where there is none.</p><p>For example, in a telecom company, there is a data set containing all the mobile customer contracts. Some of the fields are <em>contract ID </em>and <em>email address</em>. Let’s elaborate the business rules for both of them.</p><p><strong>Timeliness </strong>is the same for the whole data set — it should be refreshed daily.</p><p><em>Contract ID:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4CLXz8mZ4NlfQoS3o_jKPg.png" /></figure><p><em>Email Address:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cj_l-vQQzqXGYUUUY0Ifbw.png" /></figure><p>The key idea here is that not all the fields have the same value. For those which are central in the core business, the business rules should be strict and carefully defined. However, for secondary fields, it may not be worth spending too much time on the determination of rules.</p><h3>Data Quality Evaluation</h3><p>The goal here is to <strong>compare the metrics measured and the defined business rules.</strong> If all the metrics respect the rules then the field is validated.</p><p>In the best case of fields being evaluated, all fields will be validated and therefore the entire data asset is validated too. In the worst but simple case, all fields are wrong and the entire data asset will need correction.</p><p>The reality usually presents a mix of both valid and invalid fields in the data quality evaluation with some fields being compliant, and others not. In that case, the mandatory fields should be defined and their compliance required for validating the data asset. This validation should, however, go with some indication about <strong>how the problematic fields could affect (or not) the current or future business use cases.</strong></p><h3>Implement quality processes and enrich data</h3><p>After the data quality evaluation, the issues are underlined and have to be resolved. The best way to solve these issues is to find the root causes.</p><p>Fortunately, the data life cycles of problematic data assets are known. Therefore, it is possible to locate the stage where the problem appears, its technical and/or business reason, and the people to talk with to fix it.</p><p>To conclude, a Data Audit is divided into three phases. The first is the identification of the data asset and the investigation on its life cycle. The second is the evaluation of the data quality. For this, it is necessary to measure the 6 main metrics and compare them to the defined business rules. The output of these two phases is a clear view of any problematic data. The third and last phase consists of treating the root causes of these issues. Using the data life cycle enables us to find why and where there is a problem and with whom to interact with for a sustainable data management solution.</p><p>Adapted from <a href="https://www.amazon.com/Executing-Data-Quality-Projects-Information/dp/0123743699">Executing Data Quality Projects: Ten Steps to Quality Data and Trusted Information,</a> Danette McGilvray</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52fc1d4e2d6e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dain-studios/exploring-the-data-realm-running-a-data-audit-52fc1d4e2d6e">Exploring the Data Realm: Running a Data Audit</a> was originally published in <a href="https://medium.com/dain-studios">DAIN Studios</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>