<?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 Nicolas Jomeau on Medium]]></title>
        <description><![CDATA[Stories by Nicolas Jomeau on Medium]]></description>
        <link>https://medium.com/@nicolas.jom?source=rss-2a698f8bf6d1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*IMQchMjhrio4fdoatxx5JA.jpeg</url>
            <title>Stories by Nicolas Jomeau on Medium</title>
            <link>https://medium.com/@nicolas.jom?source=rss-2a698f8bf6d1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 22:53:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nicolas.jom/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[Terraform Lasagna - How to Layer your Deployments]]></title>
            <link>https://medium.com/elca-it/terraform-lasagna-how-to-layer-your-deployments-337100e2c962?source=rss-2a698f8bf6d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/337100e2c962</guid>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[it-architecture]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[it-infrastructure]]></category>
            <dc:creator><![CDATA[Nicolas Jomeau]]></dc:creator>
            <pubDate>Fri, 28 Apr 2023 10:13:24 GMT</pubDate>
            <atom:updated>2023-04-28T10:13:24.842Z</atom:updated>
            <content:encoded><![CDATA[<p>While many resources exist online to learn about Terraform, few actually explain how to use it in an industrial setup. In this article, we will cover how we use Terraform in Data Platform projects at ELCA for <strong>robust</strong> and <strong>fully featured deployments</strong> where <strong>multiple environments</strong> and different <strong>inter-connected Providers</strong> are required.</p><figure><img alt="Terraform logo displayed on a mouth-watering lasagna. Yummy!" src="https://cdn-images-1.medium.com/max/1024/1*M_zUNU7qjNduIF2osMDiPA.jpeg" /><figcaption>Credits to <a href="https://unsplash.com/@paulpanly">Paul Pan’s beautiful lasagna shot</a></figcaption></figure><p>Terraform is an Infrastructure-as-Code (IaC) tool that lets you define cloud and on-prem resources using a a domain specific configuration language. Since it is code-based, it is versionable with tools like Git, enabling the use of DevOps best practices to manage the infrastructure throughout its lifecycle. Just as a lasagna has multiple layers of pasta, cheese, and sauce, deploying new resources with Terraform requires layering environments and Providers.</p><h3>Layering environments</h3><p>As an industry standard for software development, using separated environments for development, testing, and production infrastructure is mandatory to avoid bugs creeping in customer facing services. As such, deploying new resources should follow the same pattern, splitting configurations in environment-specific <strong>layers</strong>:</p><ul><li>New resource is added and tested on Development environment.</li><li>If successful, it is then deployed on Test environment where it receives production-like traffic and use.</li><li>Finally, and after approval, it is deployed on Production infrastructure.</li></ul><p>In itself, such process follows the same steps that would be encountered with an application’s CI/CD. Minor differences comes from the statefullness of Terraform as it requires the state of the previous deployment to avoid overwriting existing resources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*rn5DxFT-JF4Q9fejo-DpLA.png" /><figcaption>The aforementioned process can be implemented using Terraform paired with a CI/CD tool such as Azure DevOps, Jenkins, or GitHub Actions.</figcaption></figure><p>Terraform <em>Variables</em><strong><em> </em></strong>are key to environment switching. By using a variable containing the environment name for naming or tagging resources, we ensure <strong>every resource is unique</strong> within a cloud or on-prem Provider. This in turn facilitates resource management, accounting, and monitoring of the infrastructure across environments. <strong>Naming conventions and definition are specified in a single file</strong> within a <em>locals</em> block.</p><pre>variable &quot;project&quot; {<br>  type        = string<br>  description = &quot;(Required) Project&#39;s name&quot;<br>}<br><br>variable &quot;environment&quot; {<br>  type        = string<br>  description = &quot;(Required) Environment&quot;<br>}<br><br># Unique names ensure easier monitoring and management<br>locals {<br>  prefix = &quot;${var.project}-${var.environment}&quot;<br>  <br>  virtual_network_name = &quot;${local.prefix}-vnet&quot;<br>  compute_subnet_name  = &quot;${local.virtual_network_name}-sub-compute&quot;<br>}</pre><p>If using a CI/CD tool, a deployment pipeline can provision these variables depending on which git branch the pipeline is running on and thus automate the whole infrastructure management. The tool (or user) must provide a dedicated state file for each environment to avoid corrupting their state. Ideally, deployments should be gated behind deployment windows (e.g. work hours, only Monday to Thursday, …), manual approvals, and locks to avoid costly mistakes or deployment during running data jobs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*V4wiyP-KJATbEPxbSQ_ccA.png" /><figcaption>Variables allow switching between environment configurations. Distinct state files should be used for each environment!</figcaption></figure><h3>Layering Providers</h3><p>When deploying our data platform with Terraform, we encountered a series of strange errors: after some time, deployments would start failing randomly with the <strong><em>`default auth: cannot configure default credentials`</em></strong> error message. Looking at our code (such as below) and the environment variables we were passing to our script, nothing unusual should be happening…</p><pre>provider &quot;azurerm&quot; {<br>  subscription_id = ...<br>  alias           = &quot;main&quot;<br>  features {}<br>}<br><br>resource &quot;azurerm_databricks_workspace&quot; &quot;this&quot; {<br>  provider = azurerm.main<br>  param1   = ...<br>  param2   = ...<br>}<br><br>provider &quot;databricks&quot; {<br>  azure_workspace_resource_id = azurerm_databricks_workspace.this.id<br>  host = azurerm_databricks_workspace.this.workspace_url<br>}</pre><p>As it turns out, data and managed resources have the same dependency resolution, which means they are evaluated <strong>after</strong> the Provider setups. While it is possible to declare Provider which may depend on another in a single Terraform project, doing so will inevitably lead to some cryptic errors with the dependent Provider not having any credentials. And of course these errors will appear at the worst possible time! As of this article’s time of writing, Terraform doesn’t have an easy fix to this situation.</p><p>Two solutions are however available, with one adding another tasty <strong>layer</strong>:</p><ul><li>Adding <em>depends_on</em> keywords to every resource using a dependent Provider. It reduces the frequency of the errors but also add a lot of redundant code that is easy-to-forget.</li><li>Splitting the project in 2 separate deployments for the parent Provider and the dependent Provider. It adds a bit of code such as copying locals/variables definition but it also removes any dependency error that may still happen.</li></ul><p>We retained and easily implemented the second solution. Moreover, it also allows fine-grained administration within DevOps tools by running each deployment with a different technical account and adapted rights on the infrastructure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*OxR4148XCICuRnn54ooblg.png" /><figcaption>Full deployment is done in two distinct steps, in this case for a Kubernetes Cluster on a cloud provider.</figcaption></figure><h3>Wrapping it up</h3><p>With layers in our Terraform pipelines. we found ways to make our deployments more robust and capable of managing multiple environments: using distinct resource names as well as with different state files allows to easily switch between environments, and decoupling linked Providers fixes dependencies issues. Hopefully you now have new techniques to bake your own Terraform Lasagna 😊</p><p>Article co-written and reviewed by Benjamin Audren &amp; Antoine Hue</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=337100e2c962" width="1" height="1" alt=""><hr><p><a href="https://medium.com/elca-it/terraform-lasagna-how-to-layer-your-deployments-337100e2c962">Terraform Lasagna - How to Layer your Deployments</a> was originally published in <a href="https://medium.com/elca-it">ELCA IT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Information Extraction on Distorted Documents]]></title>
            <link>https://medium.com/elca-it/information-extraction-on-distorted-document-30559f1dc9fa?source=rss-2a698f8bf6d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/30559f1dc9fa</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[computer-vision]]></category>
            <dc:creator><![CDATA[Nicolas Jomeau]]></dc:creator>
            <pubDate>Tue, 24 May 2022 09:37:03 GMT</pubDate>
            <atom:updated>2022-05-25T08:40:14.858Z</atom:updated>
            <content:encoded><![CDATA[<h3>Information Extraction on Distorted Documents with YoloV5, Rectinet and Tesseract</h3><p>You surely already have used your smartphone to scan documents. Be it with a specific camera mode or some app such as Acrobat Reader, these techniques often have the same constraints: the documents must be flattened and well exposed. This adds friction to the scanning process by forcing the user to correct the shape and exposure of its paper sheet and thus would benefit from automation. Being able to automatically perform these corrections without this added friction could be then used to create a faster feedback loop with the user: e.g. extract relevant information from a salary statement and bank reports to estimate the maximum loan a client could get.</p><p>In this article, we will build a fully end-to-end pipeline with deep learning models to extract a document from a picture, flatten it, and finally extract information from it. To flatten the document, we will need to infer its shape and to extract information from it, we will have to extract document objects from it (such as paragraphs, figures, etc...).</p><h3>The Dataset Problem</h3><p>In order to work, deep learning models must ingest a lot of training data to understand and learn the input domain they will be working with. As we are working on 2 different tasks (object detection for document and information extraction, shape detection for flattening the document), we need a dataset with appropriate training and targets features.</p><p>Unfortunately, such a dataset simply doesn’t exist and would be very costly to create: while annotating document objects is straightforward (e.g. <a href="https://www.mturk.com/">Mechanical Turk</a>), creating a dataset with the shape of distorted documents is impossible without appropriate hardware (e.g. Lidar). Fortunately, the state-of-the-art in document shape correction is now using the <a href="https://github.com/cvlab-stonybrook/doc3D-dataset">doc3D synthetic dataset</a> as well as its <a href="https://github.com/sagniklp/doc3D-renderer">renderer</a>. By taking a scanned document, a (distorted) paper mesh and a background, this renderer generates realistic looking samples as well as a mapping of the distorted document’s coordinates in the picture (also called UV mapping).</p><p>Using the renderer with the object annotated <a href="https://guillaumejaume.github.io/FUNSD/">FUNSD</a> documents, doc3D meshes, and <a href="http://indoor.hdrdb.com/">Laval Indoor HDR</a> backgrounds, we generated 2000 pictures and UV mappings (1500 for training, 500 for testing).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HRxjG6Aq7b66zN7gxocYqA.jpeg" /><figcaption>The doc3d renderer produces a realistic looking sample and a UV mapping with 3 channels for the document X/Y coordinates and whether the document is present or not.</figcaption></figure><h3>The Pipeline</h3><p>Now that we have some data to train on, we can start building the actual pipeline. It can be described in a series of 4 steps:</p><ul><li>Locate and crop the document in the picture</li><li>Detect and correct its shape</li><li>Apply some post-processing to get a “scan-like” document</li><li>Detect interesting objects in it (forms, text, tables, …)</li></ul><h4>Document Cropping</h4><p>The first step is to locate and extract a document page from the picture in order to give the most valuable information possible to the shape correction algorithm. For this, we use one of the most popular Object Detection models: <a href="https://github.com/ultralytics/yolov5">YOLOv5</a>. This model was chosen as it is extremely lightweight (2M parameters with its <em>nano</em> variant) and thus can perform real-time detection even on limited hardware. A demo is even available for <a href="https://apps.apple.com/xk/app/ultralytics/id1583935240">iPhone </a>and <a href="https://play.google.com/store/apps/details?id=com.ultralytics.ultralytics_app">Android</a>!</p><p>As of now, our dataset doesn’t contain annotation boxes for the whole document in order to train the YOLOv5n model. We fix this by using the UV mappings: if a pixel is colored, then the document is present in this pixel. By finding the minimum and maximum X/Y coordinates of these pixels, we can create the rectangular bounding box required for our training. For the next step, we also add some classes depending if the document is already flat (but warped due to perspective) or bent by simply looking at the renderer parameters used.</p><p>We then train a YOLOv5n models on the train/test set with an input size of 320px, default YOLOv5 config (300 epochs), and data augmentation with flip, scaling, mosaic tilling, as well as some hue/saturation/value randomization. As this task is fairly simple compared to the usual COCO object detection, we obtain a highly performant detection model with precise and accurate inference: mAP@0.5:0.95 is capping at 0.999 and the model only does 2 false classifications on the test set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NKPl7wv6kTdqHxuzhtU_Ow.jpeg" /><figcaption>Detecting and classifying documents with YOLOv5 works well even on real-life data!</figcaption></figure><h4>Shape Correction</h4><p>With the document now extracted, we can start correcting its shape. For this step, we use the <a href="https://github.com/DVLP-CMATERJU/RectiNet">RectiNet CNN</a> model. It is based on the famous U-Net medical segmentation model and works in 2 parts: a first U-Net takes the input image (resized to 256px) and creates a 256x256x50 features map, and a second U-Net uses these features to infer the actual shape of the document. This model doesn’t output a UV mapping as we have generated but a BW mapping instead. The BW is simply the inverse operation of the UV mapping where each pixel stores the position of the distorted document in the original picture and can be used with Pytorch’s <a href="https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html"><em>grid_sample</em></a> to flatten the document.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B-j4SYZLdBPXM23Kh_1zjQ.jpeg" /><figcaption>We can retrieve a perfectly flat document using Pytorch’s <strong><em>grid_sample</em></strong><em> and a BW mapping (the colored square).</em></figcaption></figure><p>We generate these BW target features from our dataset and finetune the already trained model for 100 epochs. As the model is pretty beefy with 80M parameters, we try reducing the number of convolutional channels or the input size to speed up its inference. These experiments didn’t give satisfying results but we believe it’s rather due to the fact we don’t have enough training data than a limiting architecture issue as these variants have overall the same MSE at end of training.</p><p>One observation from using RectiNet was that it would introduce “waves” when correcting an already flat document. To correct this behavior, we make use of the classes detected by the YOLO model in the first step: if the document is flat, we use a simple CNN to detect the document’s corners and then “pull” them to get back to a rectangular shape instead of applying RectiNet. It allows the shape correction process to be 20x faster than RectiNet while having more qualitative results.</p><h4>Post-processing</h4><p>While we (hopefully) correctly flattened our document, the result is still not anywhere near something you would get after using a scanner. Due to lighting conditions and bents, a white document can have its color altered and some of its content shadowed.</p><p>There exist some well-known algorithms to correct such artifacts. For color, we can use color balancing to bring back the altered white to a perfect white. The algorithm works by rescaling each color channel’s 95th percentile to the maximum intensity value. If you look at the distribution of channel’s values, it effectively brings them closer to maximum intensity and thus gives perfect white as all channels have similar values. Note that this balancing works well in our case as we are only applying it on mostly white documents. In the case of more diverse documents, it would require a more sophisticated method, such as manually selecting a pixel that acts as a reference white to get qualitative results or using a DNN to correct the color mapping.</p><p>For shadows, we use some median filtering to create a shadow map of the document which can then be used to remove the shadows by subtracting it from the document. As this operation darkens the document, we rescale the pixels’ channels again between the minimum and maximum intensity values. As for the white balancing, this method is highly destructive for large regions of color and thus should only be used on B&amp;W documents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XYJbAODccePeZKFXjMLGuw.jpeg" /><figcaption>Our input image (left) after white balancing (middle) and shadow removal (right).</figcaption></figure><h4>Information Extraction</h4><p>Last but not least, we want to extract meaningful information for automated processing from the corrected document. For this we use YOLOv5 again, but this time with a beefier config: we take the S variant (8M parameters) with an input size of 800px as we will be looking for small details. We train the model directly on the FUNSD dataset (150/49 train/test samples) to detect text, signatures and figures.</p><p>For such a simple task, we get some unconvincing results: precision is at 0.84, recall is at 0.78 (we are missing 22% of interesting objects!) and mAP is pretty low at 0.84 and 0.488 for the mAP@0.5 and mAP@0.5:0.95 respectively. In this case, it is often a good idea to see how the model is working and to do qualitative (instead of quantitative with metrics) visual analysis of the results. Doing so, we found out that the model is actually working fine but the low metrics were due to inconsistently annotated documents in the FUNSD dataset: paragraphs are sometimes split in multiple line objects (but detected as a whole paragraph), some objects such as checkboxes are randomly given annotations, and some annotation boxes are straight-up incorrect. Interestingly, and despite the “garbage in, garbage out” saying in machine learning, the YOLO model is able to not overfit on these wrong annotations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AQeKkmkGgkpmyV3s0xSNpA.png" /><figcaption>Ground-truth annotations (blue) vs YOLOv5 detected objects (red) on a FUNSD sample. Ground-truth is incoherent with paragraphs split into lines, missing annotated text and checkboxes sometimes having their own annotation</figcaption></figure><p>Finally, if an object is detected as text, we run it through <a href="https://github.com/tesseract-ocr/tesseract">Tesseract’s OCR LSTM</a> to extract its content. With a character-error rate of 0.27, we are in line with the results of the other state-of-the-art shape correction models. We nonetheless think this result could be improved were the FUNSD samples available in higher resolution (currently only 1000x700px).</p><h3>Conclusion</h3><p>By designing and building a full end-to-end pipeline, we are now able to efficiently scan documents even in the worse picture and paper conditions. By automating information extraction, additional algorithms or models can be plugged on top of the pipeline to further improve its capabilities: e.g. find someone’s name, address and salary on a salary statement for an insurance company without requiring the user to get a dedicated scanner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EdT86s_txFW8VUTzqE6Gyg.jpeg" /><figcaption>Real-life (and unseen) input samples and corrected outputs of the pipeline. Results are encouraging but we can see the limitations of the shadow removal algorithm with colored regions on the right sample.</figcaption></figure><p>Overall, the pipeline could still be improved: RectiNet can be trained with more samples (synthetic data generation takes time) to try smaller and more efficient variants, and some steps like shadow removal could be done using deep learning too (median filtering also takes time). Also, the next step would be to put such model in production <a href="https://medium.com/elca-it/building-an-mlops-infrastructure-on-openshift-bcb098678353">following MLOps principle</a> to access to niceties of retraining, automated deployment or monitoring.</p><p><a href="https://medium.com/elca-it/building-an-mlops-infrastructure-on-openshift-bcb098678353">Building an MLOps infrastructure on OpenShift</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30559f1dc9fa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/elca-it/information-extraction-on-distorted-document-30559f1dc9fa">Information Extraction on Distorted Documents</a> was originally published in <a href="https://medium.com/elca-it">ELCA IT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an MLOps infrastructure on OpenShift]]></title>
            <link>https://medium.com/elca-it/building-an-mlops-infrastructure-on-openshift-bcb098678353?source=rss-2a698f8bf6d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/bcb098678353</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Nicolas Jomeau]]></dc:creator>
            <pubDate>Wed, 15 Dec 2021 15:12:13 GMT</pubDate>
            <atom:updated>2021-12-15T15:12:13.852Z</atom:updated>
            <content:encoded><![CDATA[<p>Most data science projects don’t pass the PoC phase and hence never generate any business value. In 2019, <a href="https://blogs.gartner.com/andrew_white/2019/01/03/our-top-data-and-analytics-predicts-for-2019/">Gartner estimated</a> that “through 2022, only 20% of analytic insights will deliver business outcomes”. One of the main reasons for this is undoubtedly that data scientists often lack a clear vision of how to deploy their solutions into production, how to integrate them with existing systems and workflows and how to operate and maintain them. This is where MLOps comes into play, as the supposed answer to all problems regarding the industrialization of machine learning solutions.</p><p>By combining DevOps principles to common Data Science work, MLOps aims to increase automation in the machine learning lifecycle to improve reproducibility and transparency in the experiment phase, enable reliable and efficient deployment of ML models in production, and render them observable. While there exists a myriad of integrated ML platforms such as <a href="https://www.dataiku.com/">Dataiku</a>, <a href="https://www.datarobot.com/">DataRobot</a>, or <a href="https://azure.microsoft.com/en-us/services/machine-learning/mlops/">Azure</a> MLOps, my internship at <a href="https://www.elca.ch/en/data-analytics-ai">ELCA </a>focused on exploring various open-source solutions to tackle the problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pXOYGCykjBQ-y1Gz" /><figcaption>Photo by <a href="https://unsplash.com/@dawson2406?utm_source=medium&amp;utm_medium=referral">Stephen Dawson</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>According to <a href="https://martinfowler.com/articles/cd4ml.html#TechnicalComponentsOfCd4ml">ThoughtWorks’ research</a>, a good MLOps infrastructure should possess multiple features:</p><ul><li><strong>A fast experiment cycle</strong>: a data scientist can quickly try new data processing techniques, model architectures, or parameters and have the results (model artifacts and metrics) logged into one place for easy bench-marking between experiments.</li><li><strong>Continuous integration</strong>: an automated pipeline ensures that ML code passes unit tests and that models trained are above a minimum performance threshold as well as respect the product interface to avoid breaking changes.</li><li><strong>Continuous deployment</strong>: one click (if not zero) is enough to package, test, and immediately deploy a model into production. If it is an update to a previously deployed model, the update is done transparently to the user with no downtime.</li><li><strong>Monitoring</strong>: once deployed, model performance and metrics on data drift are continuously monitored to detect anomalies early and automatically raise alerts if the model or infrastructure must be updated.</li><li><strong>Scalability</strong>: the infrastructure scales according to the charge the model is experiencing to avoid spending too much and wasting costly computing resources, or too little and risking having degraded performance.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CU8Og11VE7ymV49jnje8fQ.png" /><figcaption>The common MLOps workflow — schema by author</figcaption></figure><h3>The Infrastructure</h3><p>Before deploying the tools needed to satisfy the previously mentioned features, a platform to support them must be chosen. We aim to deploy the whole project on ELCA’s infrastructure while supporting resource sharing and scaling so <a href="https://www.elcacloudservices.ch/en/elca-cloud">ELCA’s OpenShift</a> (RedHat’s packaged distribution of Kubernetes) imposed itself as the right tool for the job.</p><p>Using OpenShift (or other Kubernetes-based containerization solutions) already allows us to cover <em>Scalability </em>by controlling the number of deployed servers (via autoscaling Pods) and some part of <em>Continuous Deployment </em>by ensuring no downtime while deploying new models with Rolling Updates.</p><p>To cover our storage needs for saving datasets and trained models we use a <a href="https://min.io/">MinIO S3 Object Storage</a> server. MinIO is fully compatible with the Amazon S3 API so it can be easily substituted with another managed solution (Google GCP, Amazon S3, Azure, …) or be itself deployed on other cloud providers.</p><p>With the MLOps infrastructure configured, we can start adding one by one the building blocks of our solution to process data, train models, deploy and update them, and finally monitor the deployment.</p><h3>The Tools</h3><h4>Feature Engineering, Machine Learning and Experiment Tracking</h4><figure><img alt="ClearML (v1.0) — screenshot by author" src="https://cdn-images-1.medium.com/max/1024/1*oKGSRjcgPjRmUl9qBosbNw.png" /><figcaption>ClearML Platform — screenshot by the author</figcaption></figure><p>For the actual ML work, we decided to use the <a href="https://clear.ml/">ClearML</a> platform (v1.0), an all-in-one orchestration, data versioning, experiment tracking, and model repository solution. With as few as 2 additional lines in your Python code, you can enable ClearML to store versioned data, track metrics (and their associated plots), and save produced models binaries (pickle, h5, …) on the S3 server with a unique experiment name/ID. This data can then be reused by any other Python script simply by mentioning this ID.</p><p>In ClearML jargon, a script is called a <em>Task </em>and has access to every data and metadata on the ClearML server. This means a form of automation can be added by having tasks observing other tasks, for example, to test and validate their outputs (is the produced model good enough) or monitor newly added data (and trigger another data processing task).</p><p>Finally, you can choose where your tasks are executed: either locally or an a remote server. This allows fine-grained resource management as well as benefitting specialized hardware for specific tasks (e.g. GPUs for deep learning). Coupled with a monitoring task, cloud providers’ specialized virtual instances can be deployed on-demand to run a specific task, allowing to speed up work while spending the strict minimum on hardware.</p><h4>Continuous Integration and Deployment</h4><p>After producing a satisfying model, we must package it in an application ready for deployment. This step uses two tools well known to any DevOps engineer: <a href="https://www.jenkins.io/">Jenkins</a> and <a href="https://www.docker.com/">Docker</a>.</p><p>Jenkins is an automation tool to facilitate automating tasks (obviously!). In this project, we use it to run a sequence of actions: unit test the MLOps code, to verify the model we want to deploy is passing performance checks, to create a server using the model to run inference, to package the server in a Docker image, to run the server in a dedicated environment to perform automated integration tests, and finally to trigger the OpenShift’s rolling update. If any of these steps fails, the whole process is aborted. This ensures no faulty server can be deployed and minimizes the risks of an error.</p><p>The server is a simple <a href="https://fastapi.tiangolo.com/">FastAPI</a> web-server that loads the model and exposes web APIs to run inference. We chose FastAPI as it allows us to fully control the server behavior and to easily add new features. For example, a design choice was to use a modular approach to the server. Instead of having only an ML model, we can add modules to do additional preprocessing (web inputs aren’t in the same format as the one used for training), outlier detection, or specific features monitoring. As there is no free meal, the high customizability comes at the cost of lower computational efficiency compared to MLOps tools like Seldon or BentoML (batch-inference, gRPC instead of HTTP, automatic GPU acceleration)</p><h4>Monitoring</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vLRXSrOOrpd5l-LmaKzJWA.png" /><figcaption>Monitoring of data and model drift on Grafana — screenshot by the author</figcaption></figure><p>But simply deploying a model with a web API is not enough! To ensure it is working as expected, we need monitorability. Monitoring comes in two forms: logs (text) or metrics (numbers) describing events happening on the server. As we are mostly interested in performance metrics (time to inference, resource usage, data/predictions distributions), the former type of monitoring can be removed.</p><p>One of the most known metric logging tools combination, which we chose for this project, is the <a href="https://prometheus.io/">Prometheus</a>/<a href="https://grafana.com/">Grafana</a> stack. It allows us to both manage the collection/aggregation as well as the display of metrics. Each deployed ML server stores metrics when requests are received which Prometheus collects from a web endpoint. Using the PromQL query language, the metrics can then be filtered and aggregated to get more detailed information (rate of requests, profiling of server inference, …). Grafana plugs itself on top of the Prometheus database to create real-time and interactive visualizations from these metrics.</p><p>Both of these tools provide automatic alerting if some conditions are met. We used the alerting system of Grafana due to its ease of configuration with the web UI and the many available alerting channels: any alert can be received instantaneously by the people operating the ML project with a Slack bot, while other services (e.g. a status page or the auto-scaler) can rely on a Kafka message.</p><h3>Wrapping it up</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P0PC04GMdimpOi_LJbk9kA.jpeg" /><figcaption>MLOps architecture — schema by author</figcaption></figure><p>Thanks to Kubernetes, the whole infrastructure can be deployed via a few automated scripts and is ready to be used in a matter of minutes.</p><p>The common workflow of the Data Scientist is to load data on ClearML, process this data with Python code or more advanced means (SQL, Spark, …), train a model (with some metrics for automated model validation) as well as some modules for the ML server. Each of these models/modules is stored on the ClearML server with a unique ID.</p><p>When a good model is found, the Project Manager can decide to deploy or update the current ML server by starting a Jenkins job. This job first runs unit tests on the code, downloads the model and modules, verifies their correctness with the tagging done by the model validator, and finally packages them with FastAPI in a Docker image to be pushed on ELCA’s repository (<a href="https://jfrog.com/artifactory/">jFrog Artifactory</a>). The image is then deployed on a test environment, tested against some queries to verify the API correctness, and deployed on the production environment with a rolling update to ensure no downtime.</p><h3><strong>Conclusion</strong></h3><p>Using Open-Source technologies, we have been able to create and automate through DevOps a system that manages the full life cycle of an ML model: from the initial training to the serving, including monitoring and retraining. The biggest challenge we encountered during this internship is the ever-moving state of the MLOps landscape. Although it may change with time, a lot of tools still haven’t reached maturity and may require testing them again in a few months.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bcb098678353" width="1" height="1" alt=""><hr><p><a href="https://medium.com/elca-it/building-an-mlops-infrastructure-on-openshift-bcb098678353">Building an MLOps infrastructure on OpenShift</a> was originally published in <a href="https://medium.com/elca-it">ELCA IT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>