<?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 Wooderson on Medium]]></title>
        <description><![CDATA[Stories by Wooderson on Medium]]></description>
        <link>https://medium.com/@woodsonjhuo?source=rss-21f57b57be1c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*3aCu6Jz9zQRW8M0p</url>
            <title>Stories by Wooderson on Medium</title>
            <link>https://medium.com/@woodsonjhuo?source=rss-21f57b57be1c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 04:44:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@woodsonjhuo/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[Deploy your machine learning models with tensorflow serving and kubernetes]]></title>
            <link>https://medium.com/@woodsonjhuo/deploy-your-machine-learning-models-with-tensorflow-serving-and-kubernetes-bf0ff8de49c5?source=rss-21f57b57be1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf0ff8de49c5</guid>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Wooderson]]></dc:creator>
            <pubDate>Fri, 25 Jan 2019 16:52:28 GMT</pubDate>
            <atom:updated>2019-01-29T05:51:45.428Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Go to the profile of François Paupier" src="https://cdn-images-1.medium.com/proxy/1*g_-XyiegzyKWEviMuxs0ZQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*JbRs8n8Vm3xsyhuHD4GuFg.png" /></figure><p>Machine learning applications are booming and yet there is not a lot of tools available for Data Engineers to integrate those powerful models in production systems. Here I discuss how tensorflow-serving can help you accelerate delivering models in productions. This blog post is about serving machine learning models — <em>what does it mean?</em></p><blockquote>Serving is how you apply a ML model after you’ve trained it — Noah Fiedel Software Engineer working on tensorflow serving</blockquote><p>To illustrate the capabilities of <a href="https://www.tensorflow.org/serving/">tensorflow serving</a>, I will go through the steps of serving an object detection model. Find all the code related to this article on my GitHub: <a href="https://github.com/fpaupier/tensorflow-serving_sidecar">https://github.com/fpaupier/tensorflow-serving_sidecar</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*u1gb4jbIjJmeNDxtkONWXA.png" /><figcaption>Summary of a machine learning pipeline — here we focus on serving the model</figcaption></figure><p><em>Tensorflow serving in a nutshell</em></p><p>Tensorflow serving enables you to seamlessly serve your machine learning models.</p><ul><li>Deploy a new version of your model and let tensorflow serving gracefully finish current requests while starting to serve new requests with the new model.</li><li>Separate concerns, data scientists can focus on building great models while Ops can focus on building highly resilient and scalable architectures that can serve those models.</li></ul><p>Before going online it’s good to make sure your server works on local. I’m giving the big steps here, find more documentation in the project readme . <br><a href="https://github.com/fpaupier/tensorflow-serving_sidecar/blob/master/docs/setup.md">Take a look at the setup steps</a> to make sure you can take the most out of this tutorial:</p><ol><li>git clone <a href="https://github.com/fpaupier/tensorflow-serving_sidecar">https://github.com/fpaupier/tensorflow-serving_sidecar</a> , create a python3.6.5 virtual env and install the requirements.txt</li><li>Get tensorflow serving docker image docker pull tensorflow/serving</li><li>Get a model to serve → I use this one, it performs object detection <a href="http://download.tensorflow.org/models/object_detection/faster_rcnn_resnet101_coco_2018_01_28.tar.gz">faster_rcnn_resnet101_coco</a></li><li>Go to the model directory and rename the saved model subdirectory with a version number, since we are doing a v1 here let’s call it 00001 (it has to be figures). We do this because tensorflow serving docker image search for folders named with that convention when searching for a model to serve.</li><li>Now run the tensorflow server:</li></ol><pre># From tensorflow-serving_sidecar/<br>docker run -t --rm -p 8501:8501 \<br> -v &quot;$(pwd)/data/faster_rcnn_resnet101_coco_2018_01_28:/models/faster_rcnn_resnet&quot; \<br> -e MODEL_NAME=faster_rcnn_resnet \<br> tensorflow/serving &amp;</pre><p>Just a note before going further:</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*oCzPBR-ZYFGoKHCBEBhgag.jpeg" /><figcaption>docker -v arg in our use case</figcaption></figure><p>Here we bind the port of the container and the localhost. Thus when we will call for inference on localhost:8501 we will actually call the tensorflow server.</p><p>You also notice we link our localhost directory faster_rcnn_resnet101_coco_2018_01_28 — where the model is stored — with the container /models/faster_rcnn_resnet path.</p><p>Just keep in mind that at this point the savedModel.pb is solely on your machine, not in the container.</p><p>6. Perform the client call:</p><pre># Don&#39;t forget to activate your python3.6.5 venv</pre><pre># From tensorflow-serving_sidecar/<br>python client.py --server_url &quot;http://localhost:8501/v1/models/faster_rcnn_resnet:predict&quot; \<br>--image_path &quot;$(pwd)/object_detection/test_images/image1.jpg&quot; \<br>--output_json &quot;$(pwd)/object_detection/test_images/out_image1.json&quot; \<br>--save_output_image &quot;True&quot; \<br>--label_map &quot;$(pwd)/data/labels.pbtxt&quot;</pre><p>Go check the path specified by --output_json and enjoy the result. (json and jpeg output available)</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*7rMW1PVA7g6Sbh4w8xFtUg.jpeg" /><figcaption>expected inference with our object detection model</figcaption></figure><p>Great, now that our model works well, let’s deploy it on the cloud.</p><p>In a production setting, you want to be able to scale as the load is increasing on your app. You don’t want your server to be overwhelmed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*Jx5Dj0s00JbFtMosWDB0Sw.png" /><figcaption>An exhausted tensorflow server directly exposed over the network</figcaption></figure><p>To avoid this issue, you will use a kubernetes cluster to serve your tensorflow-server app. Main improvements to expect:</p><ul><li>The load will be balanced among your replicas without you having to think about it.</li><li>Do you want to deploy a new model with no downtime? No problem, kubernetes got your back. Perform a rolling update to progressively serve your new model while gracefully terminating the current requests on the former model.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*SZ6-Iwo1fgraBQARcsCfqA.png" /><figcaption>a tensorflow server application running on many replicas in a k8s cluster, ensuring high availability to users</figcaption></figure><p><strong>Let’s dive in</strong></p><p>First, we want to create a complete docker image with the object detection model embedded. Once this is done, we will deploy it on a kubernetes cluster. I run my example on <a href="https://cloud.google.com/">Google Cloud Platform</a> because the free tier makes it possible to run this tutorial for free. To help you set up your cloud environment at GCP you can check <a href="https://github.com/fpaupier/tensorflow-serving_sidecar/blob/master/docs/gcp_setup.md">my tutorial here</a>.</p><ol><li>Run a serving image as a daemon:</li></ol><pre>docker run -d --name serving_base tensorflow/serving</pre><p>2. Copy the faster_rcnn_resnet101_coco model data to the container&#39;s models/ folder:</p><pre># From tensorflow-serving_sidecar/<br>docker cp $(pwd)/data/faster_rcnn_resnet101_coco_2018_01_28 serving_base:/models/faster_rcnn_resnet</pre><p>3. Commit the container to serve the faster_rcnn_resnet model:</p><pre>docker commit --change &quot;ENV MODEL_NAME faster_rcnn_resnet&quot; serving_base faster_rcnn_resnet_serving</pre><p><em>Note:</em> if you use a different model, change faster_rcnn_resnet in the --change argument accordingly.</p><p>faster_rcnn_resnet_serving will be our new serving image. You can check this by running docker images, you should see a new docker image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*NO7yue0KJ_apO8I9-X0_8g.png" /><figcaption>docker images result after creating a custom tensorflow-serving image</figcaption></figure><p>4. Stop the serving base container</p><pre>docker kill serving_base<br>docker rm serving_base</pre><p>Great, the next step is to test our brand new faster_rcnn_resnet_serving image.</p><p>Before deploying our app on kubernetes, let’s make sure it works correctly.</p><pre>docker run -p 8501:8501 -t faster_rcnn_resnet_serving &amp;</pre><p><em>Note:</em> Make sure you have stopped (docker stop &lt;CONTAINER_NAME&gt;) the previously running server otherwise the port 8501 may be locked.</p><p>2. We can use the same client code to call the server.</p><pre># From tensorflow-serving_sidecar/<br>python client.py --server_url &quot;http://localhost:8501/v1/models/faster_rcnn_resnet:predict&quot; \<br>--image_path &quot;$(pwd)/object_detection/test_images/image1.jpg&quot; \<br>--output_json &quot;$(pwd)/object_detection/test_images/out_image2.json&quot; \<br>--save_output_image &quot;True&quot; \<br>--label_map &quot;$(pwd)/data/labels.pbtxt&quot;</pre><p>We can check we have the same Ok let’s run this on a kubernetes cluster now.</p><p>Unless you already have run a project on GCP, I advise you to check the <a href="https://github.com/fpaupier/tensorflow-serving_sidecar/blob/master/docs/gcp_setup.md">Google Cloud setup steps</a>.</p><p>I assume you have created and logged in a gcloud project named tensorflow-serving</p><p>You will use the container image faster_rcnn_resnet_serving built previously to deploy a serving cluster with <a href="https://kubernetes.io/">Kubernetes</a> in the <a href="https://cloud.google.com/">Google Cloud Platform</a>.</p><ol><li>Login to your project, first list the available projects with gcloud projects list, select the PROJECT_ID of your project and run</li></ol><pre># Get the PROJECT_ID, not the name<br>gcloud projects list</pre><pre># Set the project with the right PROJECT_ID, i.e. for me it is tensorflow-serving-229609<br>gcloud config set project tensorflow-serving-229609<br>gcloud auth login</pre><p>2. Create a container cluster</p><ul><li>First, we create a <a href="https://cloud.google.com/container-engine/">Google Kubernetes Engine</a> cluster for service deployment. Due to the free trial limitation, you cannot do more than 2 nodes here, you can either upgrade or go with the two nodes which will be good enough for our use case. (<em>You are limited to a quota of 8 CPUs in your free trial.</em>)</li></ul><pre>gcloud container clusters create faster-rcnn-serving-cluster --num-nodes 2 --zone &#39;us-east1&#39;</pre><p>You may update the zone arg, you can choose among <em>e.g</em>: europe-west1, asia-east1 - You check all the zones available with gcloud compute zones list.<br>You should have something like that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*MXrZekqAqVIDQShZ-k7QrQ.png" /><figcaption>kubernetes cluster creation output</figcaption></figure><p>3. Set the default cluster for gcloud container command and pass cluster credentials to <a href="https://kubernetes.io/docs/reference/kubectl/overview/">kubectl</a>.</p><pre>gcloud config set container/cluster faster-rcnn-serving-cluster<br>gcloud container clusters get-credentials faster-rcnn-serving-cluster --zone &#39;us-east1&#39;</pre><p>You should have something like this afterward:</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*fZ3THPtLIHBWvn6ca0kANA.png" /><figcaption>gcloud container clusters get-credentials output</figcaption></figure><p>4. Upload the custom tensorflow-serving docker image we built previously. Let’s push our image to the <a href="https://cloud.google.com/container-registry/docs/">Google Container Registry</a> so that we can run it on Google Cloud Platform.</p><p>Tag the faster_rcnn_resnet_serving image using the Container Registry format and our project id, change the tensorflow-serving-229609 with your PROJECT_ID. Also change the tag at the end, here it&#39;s our first version so I set the tag to v0.1.0.</p><pre>docker tag faster_rcnn_resnet_serving gcr.io/tensorflow-serving-229609/faster_rcnn_resnet_serving:v0.1.0</pre><p>If you run docker images, you now see an additional gcr.io/tensorflow-serving-229609/faster_rcnn_resnet_serving:v0.1.0 image.</p><p>This gcr.io prefix allows us to push the image directly to the Container registry,</p><pre># To do only once<br>gcloud auth configure-docker</pre><pre>docker push gcr.io/tensorflow-serving-229609/faster_rcnn_resnet_serving:v0.1.0</pre><p>You have successfully pushed your image on GCP Container Registry, you can check it online:</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*QoM7Wpdm33TZil_5xX9oGQ.png" /><figcaption>docker image successfully pushed on Google Container Registry</figcaption></figure><p>5. Create Kubernetes Deployment and Service</p><p>The deployment consists of a single replica of faster-rcnn inference server controlled by a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/">Kubernetes Deployment</a>. The replica is exposed externally by a <a href="https://kubernetes.io/docs/concepts/services-networking/service/">Kubernetes Service</a> along with an <a href="https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/">External Load Balancer</a>.</p><p>Using a single replica does not really make sense. I just do so to pass within the free tier. Load balancing if you have only one instance to direct your query on is useless. In a production setup, use multiple replicas.</p><p>We create them using the example Kubernetes config <a href="https://github.com/fpaupier/tensorflow-serving_sidecar/blob/master/faster_rcnn_resnet_k8s.yaml">faster_rcnn_resnet_k8s.yaml</a>. You simply need to update the docker image to use in the file, replace the line image: &lt;YOUR_FULL_IMAGE_NAME_HERE&gt; with your actual image full name, it looks like something like that:</p><pre>image: gcr.io/tensorflow-serving-229609/faster_rcnn_resnet_serving@sha256:9f7eca6da7d833b240f7c54b630a9f85df8dbdfe46abe2b99651278dc4b13c53</pre><p>You can find it in your container registry:</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*5d9pt3RpzfmXMrkZCcHXzw.png" /><figcaption>find your docker full image name on google container registry</figcaption></figure><p>And then run the following command</p><pre># From tensorflow-serving_sidecar/<br>kubectl create -f faster_rcnn_resnet_k8s.yaml</pre><p>To check the status of the deployment and pods use the kubectl get deployments for the whole deployment, kubectl get pods to monitor each replica of your deployment and kubectl get services for the service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*Bbh5PObnAp86RDNwade-jw.png" /><figcaption>sanity check for deployment</figcaption></figure><p>It can take a while for everything to be up and running. The service external IP address is listed next to LoadBalancer Ingress. You can check it with the kubectl describe service command:</p><pre>kubectl describe service faster-rcnn-resnet-service</pre><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*oVF9YMFtJDvlJZI6hXVTqg.png" /><figcaption>find the IP address to query upon to perform inference</figcaption></figure><p>And finally, let’s test this. We can use the same <a href="https://github.com/fpaupier/tensorflow-serving_sidecar/blob/master/client.py">client code</a>. Simply replace the previously used localhost in the --server-url arg with the IP address of the LoadBalancer Ingress as specified above.</p><pre># From tensorflow-serving_sidecar/<br>python client.py --server_url &quot;http://34.73.137.228:8501/v1/models/faster_rcnn_resnet:predict&quot; \<br>--image_path &quot;$(pwd)/object_detection/test_images/image1.jpg&quot; \<br>--output_json &quot;$(pwd)/object_detection/test_images/out_image3.json&quot; \<br>--save_output_image &quot;True&quot; \<br>--label_map &quot;$(pwd)/data/labels.pbtxt&quot;</pre><p>Tensorflow serving offers a great basis on which you can rely to quickly deploy your model in production with very little overhead.</p><ul><li>Containerization of machine learning applications for their deployment enables to <em>separate the concerns </em>between Ops and Data Scientists</li><li>Container orchestration solutions such as Kubernetes combined with tensorflow-serving offer the possibility to deploy high availability models in minutes even for people not familiar with distributed computing.</li></ul><p><strong>Resources 📚</strong></p><ul><li>Tensorflow serving explained by Noah Fiedel, Software Engineer at Google who worked on Tensorflow Serving. It gives insights on how it has been built and for which purposes <a href="https://www.youtube.com/watch?v=q_IkJcPyNl0">https://www.youtube.com/watch?v=q_IkJcPyNl0</a></li><li>Libraries of pre-trained models freely available <a href="https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md">https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md</a></li><li>Tyler Labonte medium post for exporting a tensorflow model as a saved checkpoints <a href="https://medium.com/@tmlabonte/serving-image-based-deep-learning-models-with-tensorflow-servings-restful-api-d365c16a7dc4">https://medium.com/@tmlabonte/serving-image-based-deep-learning-models-with-tensorflow-servings-restful-api-d365c16a7dc4</a></li><li>An example of how cumbersome it can be to serve an ML model with no proper framework <a href="https://towardsdatascience.com/how-to-build-and-deploy-a-lyrics-generation-model-framework-agnostic-589f3026fd53">https://towardsdatascience.com/how-to-build-and-deploy-a-lyrics-generation-model-framework-agnostic-589f3026fd53</a></li><li>Cloud ML, Google managed solution for deploying ML models: <a href="https://cloud.google.com/ml-engine/docs/tensorflow/deploying-models">https://cloud.google.com/ml-engine/docs/tensorflow/deploying-models</a></li></ul><p><em>Originally published at </em><a href="https://towardsdatascience.com/deploy-your-machine-learning-models-with-tensorflow-serving-and-kubernetes-9d9e78e569db"><em>towardsdatascience.com</em></a><em> on January 25, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf0ff8de49c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python]]></title>
            <link>https://medium.com/@woodsonjhuo/python-b001d303c2c2?source=rss-21f57b57be1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b001d303c2c2</guid>
            <dc:creator><![CDATA[Wooderson]]></dc:creator>
            <pubDate>Wed, 14 Nov 2018 23:07:34 GMT</pubDate>
            <atom:updated>2018-11-14T23:07:34.509Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.techbeamers.com/essential-python-tips-tricks-programmers/">https://www.techbeamers.com/essential-python-tips-tricks-programmers/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b001d303c2c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[System Design Links:]]></title>
            <link>https://medium.com/@woodsonjhuo/system-design-links-935aeca091db?source=rss-21f57b57be1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/935aeca091db</guid>
            <dc:creator><![CDATA[Wooderson]]></dc:creator>
            <pubDate>Wed, 12 Sep 2018 05:39:39 GMT</pubDate>
            <atom:updated>2018-09-12T05:49:26.597Z</atom:updated>
            <content:encoded><![CDATA[<p>System Design Links:</p><ul><li><a href="https://www.jyt0532.com/2017/03/27/system-design/">系統設計 - Design cache · jyt0532&#39;s Blog</a></li><li><a href="https://github.com/checkcheckzz/system-design-interview">GitHub - checkcheckzz/system-design-interview: System design interview for IT companies</a></li><li><a href="https://www.interviewbit.com/courses/system-design/">System Design - InterviewBit</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=935aeca091db" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>