<?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 Haohui on Medium]]></title>
        <description><![CDATA[Stories by Haohui on Medium]]></description>
        <link>https://medium.com/@liuhh02?source=rss-500dff1f8d3b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*dyJynQBln9aumwBWYpltGw.jpeg</url>
            <title>Stories by Haohui on Medium</title>
            <link>https://medium.com/@liuhh02?source=rss-500dff1f8d3b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 22 Jun 2026 12:08:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@liuhh02/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[So… How exactly is AI being used to detect COVID-19?]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/data-science/so-how-exactly-is-ai-being-used-to-detect-covid-19-d0dff155881f?source=rss-500dff1f8d3b------2"><img src="https://cdn-images-1.medium.com/max/1827/1*Eslh3FcU-LBZRWKuwEMqug.png" width="1827"></a></p><p class="medium-feed-snippet">Demystifying the mathematics behind Deep Learning &amp; Convolutional Neural Networks (CNN)</p><p class="medium-feed-link"><a href="https://medium.com/data-science/so-how-exactly-is-ai-being-used-to-detect-covid-19-d0dff155881f?source=rss-500dff1f8d3b------2">Continue reading on TDS Archive »</a></p></div>]]></description>
            <link>https://medium.com/data-science/so-how-exactly-is-ai-being-used-to-detect-covid-19-d0dff155881f?source=rss-500dff1f8d3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0dff155881f</guid>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[covid19]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Haohui]]></dc:creator>
            <pubDate>Thu, 18 Feb 2021 16:58:27 GMT</pubDate>
            <atom:updated>2021-02-18T16:58:27.221Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[I Built a Telegram Bot to Combat Food Wastage — Here’s How]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/data-science/i-built-a-telegram-bot-to-combat-food-wastage-heres-how-293259a1bd32?source=rss-500dff1f8d3b------2"><img src="https://cdn-images-1.medium.com/max/1844/1*i-ZiknOAvYAo0N9R7k1hPg.png" width="1844"></a></p><p class="medium-feed-snippet">A Complete Python Guide to Telegram Bot Creation using python-telegram-bot</p><p class="medium-feed-link"><a href="https://medium.com/data-science/i-built-a-telegram-bot-to-combat-food-wastage-heres-how-293259a1bd32?source=rss-500dff1f8d3b------2">Continue reading on TDS Archive »</a></p></div>]]></description>
            <link>https://medium.com/data-science/i-built-a-telegram-bot-to-combat-food-wastage-heres-how-293259a1bd32?source=rss-500dff1f8d3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/293259a1bd32</guid>
            <category><![CDATA[telegram]]></category>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Haohui]]></dc:creator>
            <pubDate>Tue, 05 May 2020 13:51:42 GMT</pubDate>
            <atom:updated>2020-05-07T09:11:52.253Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How to Deploy a Telegram Bot using Heroku for FREE]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/data-science/how-to-deploy-a-telegram-bot-using-heroku-for-free-9436f89575d2?source=rss-500dff1f8d3b------2"><img src="https://cdn-images-1.medium.com/max/2600/0*5q3C8bP9QzM7SKAW" width="2968"></a></p><p class="medium-feed-snippet">Using the python-telegram-bot library</p><p class="medium-feed-link"><a href="https://medium.com/data-science/how-to-deploy-a-telegram-bot-using-heroku-for-free-9436f89575d2?source=rss-500dff1f8d3b------2">Continue reading on TDS Archive »</a></p></div>]]></description>
            <link>https://medium.com/data-science/how-to-deploy-a-telegram-bot-using-heroku-for-free-9436f89575d2?source=rss-500dff1f8d3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9436f89575d2</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[heroku]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[telegram]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Haohui]]></dc:creator>
            <pubDate>Mon, 04 May 2020 16:18:23 GMT</pubDate>
            <atom:updated>2020-05-06T14:52:25.929Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Adversarial Attacks in Machine Learning and How to Defend Against Them]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/data-science/adversarial-attacks-in-machine-learning-and-how-to-defend-against-them-a2beed95f49c?source=rss-500dff1f8d3b------2"><img src="https://cdn-images-1.medium.com/max/2000/1*VMW1j6A_kh4LyuNFyEw3hw.png" width="2000"></a></p><p class="medium-feed-snippet">Notes from the Keynote Speech by Professor Ling Liu at the 2019 IEEE Big Data Conference</p><p class="medium-feed-link"><a href="https://medium.com/data-science/adversarial-attacks-in-machine-learning-and-how-to-defend-against-them-a2beed95f49c?source=rss-500dff1f8d3b------2">Continue reading on TDS Archive »</a></p></div>]]></description>
            <link>https://medium.com/data-science/adversarial-attacks-in-machine-learning-and-how-to-defend-against-them-a2beed95f49c?source=rss-500dff1f8d3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2beed95f49c</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[adversarial-attack]]></category>
            <dc:creator><![CDATA[Haohui]]></dc:creator>
            <pubDate>Thu, 19 Dec 2019 05:34:36 GMT</pubDate>
            <atom:updated>2019-12-19T05:34:36.982Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Responsible Data Science]]></title>
            <link>https://medium.com/data-science/responsible-data-science-part-1-1906062fe486?source=rss-500dff1f8d3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1906062fe486</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Haohui]]></dc:creator>
            <pubDate>Thu, 12 Dec 2019 09:51:12 GMT</pubDate>
            <atom:updated>2021-04-19T04:47:26.747Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Hidden Dangers of Data Science</h3><h4>Notes from the IEEE Big Data Conference Keynote Speech by Lise Getoor</h4><p>Data science, machine learning, artificial intelligence. These are all buzz words that have emerged in our society. We have grown increasingly reliant on these technologies, but this growing reliance also raises questions about how justified we are in giving our complete trust to these technologies. Machine learning and deep learning are known famously to be a black box — we feed data into the model and come up with some results that we just take for granted, without really questioning how these results were obtained, and whether the process is justified. This issue formed the backdrop of the keynote presentation by Professor Lise Getoor at the 2019 IEEE Big Data Conference held in Los Angeles on 10 December 2019, and I will now give an overview of the enlightening talk she gave.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*VxVk6oPSo6CMqtjB.png" /><figcaption>Image by <a href="https://pixabay.com/users/manfredsteger-1848497/">manfredsteger</a> from <a href="https://pixabay.com/vectors/pixel-cells-techbot-teach-o-bot-3947912/">Pixabay</a></figcaption></figure><h4>Background</h4><p>Data science has increasingly found itself in the spotlight, with increasing coverage and attention all over the world. But whenever we see data science in the news, it is mostly for something bad. For instance, many of us are familiar with the Cambridge Analytica scandal which harvested the personal data of millions of peoples’ Facebook profiles without their consent and used it for political advertising purposes. Another example is how scientists proclaimed to have created a model able to <a href="https://www.neowin.net/news/ai-supposedly-learns-to-identify-criminals-by-their-faces-takes-us-back-to-the-19th-century/">infer criminality based on facial images</a>.</p><p>In the keynote speech, Professor Getoor mainly focused on responsible data science in machine learning, which I will now outline.</p><h4>Machine Learning — A short introduction</h4><p>Machine learning has undergone several revolutions, with several themes emerging over the past century, starting from Concept Learning, Statistical Learning, Optimization-based learning to Deep Learning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KGctY1MtJFLtBSz8p1E-cA.png" /><figcaption>Image taken from <a href="https://users.soe.ucsc.edu/~getoor/Talks/IEEE-Big-Data-Keynote-2019.pdf">IEEE Big Data 2019 Keynote</a>. Reposted with permission</figcaption></figure><p>Concept Learning revolves around how machines can learn logically consistent hypothesis that can correctly label the positive and negative samples correctly. In the 1980s, machine learning moved towards statistical learning, in particular, probabilistic methods, with a focus on learning a hypothesis that maximizes probability and data likelihood. Next, machine learning moved towards optimization-based, for example, Support Vector Machines (SVM) where hypotheses minimize some loss function. Now we are in the neural-inspired learning age of deep learning which represents the hypothesis as a neural network.</p><h4>Training and Testing</h4><p>In essence, the goal of training in machine learning is to minimize the loss between the target label and the predicted label. This is formulated mathematically as such:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z1lq3P3xxv7Mshk-5ry7Dw.png" /><figcaption>Image taken from <a href="https://users.soe.ucsc.edu/~getoor/Talks/IEEE-Big-Data-Keynote-2019.pdf">IEEE Big Data 2019 Keynote</a>. Reposted with permission</figcaption></figure><p>During the testing phase, the learned model is tested to determine how well it is able to predict the predicted label. Error is then calculated by the sum of the loss between the target label and the predicted label, formulated mathematically as such:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cIqZ5vRy_5AwrlUnbaApdg.png" /><figcaption>Image taken from <a href="https://users.soe.ucsc.edu/~getoor/Talks/IEEE-Big-Data-Keynote-2019.pdf">IEEE Big Data 2019 Keynote</a>. Reposted with permission</figcaption></figure><p>This seems relatively straight forward enough — train a model to reduce the loss and you are able to objectively quantify its performance by calculating the error.</p><p>So what could possibly go wrong? It turns out, many.</p><h4>The Things That Could Go Wrong</h4><p>In total, Professor Getoor covered 7 issues that could go wrong: Formalization of the problem, dealing with high dimensional data, measuring error, interpretability in deep learning, causal modelling, bias and data dignity. These are what the problems are:</p><h4>Issue #1 — Formalization</h4><p>It may seem as though coming up with the training objective is easy, but in fact, every time we train a model, we are making some frame of reference commitment to what the data are, what the labels are, and what the loss function is.</p><p>Firstly, the transformation of raw data into feature vectors requires us to make a frame of reference commitment because raw data always contains much more social and historical context which cannot be represented by the feature vector. This means we would miss much of this important information from human data whenever we transform the raw data.</p><p>Next, the choice of labels is also problematic, because who gets to define the labels? Labels can only be proxies for true data, never the real replacement.</p><p>Lastly, the choice of loss function is important as well because different loss functions penalize errors differently, and trade-offs between the factors influencing model performance are often over-simplified and force-fitted into these loss functions which may not truly represent the task requirements.</p><p>Therefore, there is a need for some criteria to evaluate if the chosen frame of reference is appropriate, with a criterion known as “Structural Plausibility”- that there should be a plausible scientific connection between the input features and the output label. If not, no matter how well your classifier performs, you should reject the hypothesis. For instance, the inferring of criminality based on facial images does not pass this test, because the purported “scientific connection” between the facial images (the input features) and the classification (the output label) is not scientific at all. Instead, it was based on the method in which the images were chosen. Non-criminal images were likely manually chosen by the experimenter to convey a positive impression. In contrast, the criminal images were likely selected neither by the individual depicted nor with the aim of casting an individual in a favourable light. Therefore, the model is essentially a “smile detector” and the connection purported to be discovered is not, in fact, a “plausible scientific connection”.</p><h4>Issue #2 — High Dimensional Data</h4><p>The next problem with machine learning is the huge reliance on data, both for training and testing. The issue arises with high dimensional data, because the danger of overfitting is much higher. This is also followed by numerous problems:</p><ol><li>The curse of dimensionality means that our intuitions break down in high dimensions, so although we may still be able to rely on our intuitions when dealing with low dimensional data, we cannot do the same with high dimensional data.</li><li>The likelihood of finding a random subset of features that are predictive but actually have no correlation is high simply by virtue of the huge dimension of the data.</li><li>The required sample size for generalization grows proportionally with dimension, hence the sample size required is exponentially larger with high dimensional data.</li></ol><p>One example is how the NSA tried <a href="https://www.popsci.com/nsas-skynet-might-not-be-able-to-tell-what-makes-terrorist/">using machine learning to predict the cell phone usage of terrorists cell phone usage</a>. This was highly problematic because they used 80 variables for each cell phone user with only 7 known terrorists. When they tried testing the model in the wild, it ended up identifying an Al Jazeera reporter covering Al Qaeda as a potential terrorist! This shows how high dimensional data often leaves us more prone to errors because the sample size requirement is much higher.</p><h4>Issue #3 — Measuring Error</h4><p>The next issue that arises is the issue of measuring model performance. Researchers always proclaim that their new state-of-the-art models have reached XX accuracy or F1, and so on. However, such a claim always comes with many unspoken conditions, that the dataset has a well-defined population with both the training and test data being representative samples of the population. However, this almost never holds in practice. The image below illustrates the problem wonderfully:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wI22KPKWqaWj7sDEtrEjag.png" /><figcaption>Image taken from <a href="https://users.soe.ucsc.edu/~getoor/Talks/IEEE-Big-Data-Keynote-2019.pdf">IEEE Big Data 2019 Keynote</a>. Reposted with permission</figcaption></figure><p>The learned model, represented in green above, may seem to fit the true model initially. However, upon further testing, it may become evident later on that the learned model does not actually represent the true model.</p><h4>Issue #4 — Interpretability in Deep Learning</h4><p>Interpretability in deep learning has received an increased amount of interest in the past few years. This is important because although deep learning models may achieve excellent results, we cannot know for sure if the results are because the model has really learned the important features, or that the model actually learned the wrong features and it just so happened that the features remained unchanged for the images in the same category. The trouble comes when the wrong feature is changed while the important features remain the same. If the model learned the wrong features, it may then make a wrong prediction.</p><p>One example is the paper titled “Why Should I Trust You” Explaining the Predictions of Any Classifier” by Ribeiro et al. in 2016. They trained a model to classify between a Husky and a Wolf, but it turned out to be classifying the snow and grass in the background of the picture. It turned out that the snow in the image was used to classify the image as ‘wolf’, whereas grass in the image was used to classify the image as ‘husky’. As a result, when a husky was pictured with a snow background, it was wrongly classified as a wolf.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vXOAiczh-Q4shTB-.png" /><figcaption>Image taken from Ribeiro, M. T., Singh, S., &amp; Guestrin, C. (2016, August). &quot; Why should i trust you?&quot; Explaining the predictions of any classifier. In <em>Proceedings of the 22nd ACM SIGKDD international conference on knowledge discovery and data mining</em> (pp. 1135-1144).</figcaption></figure><h4>Issue #5 — Causal Modeling: Correlation VS Causation</h4><p>The issue of correlation versus causation is yet another topic discussed frequently, especially in statistics. The idea is that CORRELATION helps with prediction; if X and Y are positively correlated, then if we observe a high X, then we would expect to see high Y. On the other hand, CAUSATION is needed for decision making; if X and Y are causally connected, then if we manipulate the value of X while keeping everything else constant, then the value of Y will definitely change. The issue with confusing a correlation as causation is with CONFOUNDERS, where a correlation is often due to one or more confounding latent variables that is a hidden cause of both X and Y.</p><p>For example, it may seem as though a rise in sales of ice creams would lead to a rise in the number of shark attacks. To the untrained eye, it may seem as though the rise in sales causes the rise in attacks. However, there is actually a confounder — the weather. It might just be the case that the hot weather was leading to a rise in ice cream sales as well as a rise in shark attacks (because more people go to the beach thanks to the good weather), and there was only a correlation and not causation between the sales of ice cream and rise in shark attacks.</p><h4>Issue #6 — Bias and Fairness</h4><p>Bias in machine learning can be categorized into three categories — data bias, automation bias and algorithmic discrimination.</p><p>Firstly, data bias refers to the choice of dataset. The contents of the dataset are affected by many factors ranging from selection bias, institutional bias and societal bias. As the saying goes, garbage in, garbage out. If the input to the system is biased, then the output will be biased. For instance, Amazon came under fire for <a href="https://www.businessinsider.com/amazon-built-ai-to-hire-people-discriminated-against-women-2018-10">building an AI tool to hire people that discriminated against women</a>. The reason is simple — the training set contained mainly male resumes, hence the model began to learn that males would be better employees than females based merely on the sheer amount of male resumes.</p><p>Secondly, automation bias refers to the preference that we human beings have for suggestions from automated decision-making systems and often ignore contradictory information. We tend to believe the decisions made by automated systems just because they are automated, without sparing additional thought for the validity and justifiability of these decisions. The danger then comes when decision makers start abdicating decision responsibility to algorithms. It is especially tempting to rely on algorithms for making hard decisions, hence this would affect accountability.</p><p>Finally, algorithmic discrimination refers to the phenomenon whereby algorithms can amplify, operationalize and finally legitimize institutional bias. When algorithms legitimize these biases, we may reach a point whereby we no longer question these biases that we used to look on with suspicion and instead embrace them. This would be extremely dangerous to our society.</p><p>This brings us to the problem of fairness. First of all, who is the fairness for? Different metrics matter to different stakeholders. For instance, a judge would want to minimize false negatives in trials, whereas a defendant would want to reduce the likelihood of false positives, of being convicted wrongly. When dealing with issues of fairness and bias, we must always keep in mind that fairness is a social and ethical concept and not a statistical concept. Bias is subjective and hence must be considered relative to the task.</p><h4>Issue #7 — Data Dignity</h4><p>This is the last issue raised. Data is the new currency and the data we each produce are highly valuable. However, our data are frequently misused without our consent and awareness, for example in the Cambridge Analytica scandal. Hence, there is a need for data dignity, which is the ability to understand and control how your data is being used. There should be also a concept of “data as labor”, which is the ability to get paid for use of your data. This is only right because data is the new currency of the world.</p><h4>Conclusion</h4><p>We have gone through a brief overview of machine learning as well as covered the seven problems that could go wrong with machine learning. This is definitely food for thought as we ponder about how we often give our unquestioning trust to machine learning algorithms and the implications this can have on our society.</p><p>A huge thanks to Professor Getoor for the wonderful and insightful keynote speech on responsible data science, it was truly enlightening.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1906062fe486" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/responsible-data-science-part-1-1906062fe486">Responsible Data Science</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[I Built a Music Sheet Transcriber — Here’s How]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/data-science/i-built-a-music-sheet-transcriber-heres-how-74708fe7c04c?source=rss-500dff1f8d3b------2"><img src="https://cdn-images-1.medium.com/max/1372/1*5SPwvFrV8Gty8Ny-vhzCUg.png" width="1372"></a></p><p class="medium-feed-snippet">Translating from notes to ABC notation has never been so easy!</p><p class="medium-feed-link"><a href="https://medium.com/data-science/i-built-a-music-sheet-transcriber-heres-how-74708fe7c04c?source=rss-500dff1f8d3b------2">Continue reading on TDS Archive »</a></p></div>]]></description>
            <link>https://medium.com/data-science/i-built-a-music-sheet-transcriber-heres-how-74708fe7c04c?source=rss-500dff1f8d3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/74708fe7c04c</guid>
            <category><![CDATA[music]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Haohui]]></dc:creator>
            <pubDate>Tue, 26 Nov 2019 16:12:51 GMT</pubDate>
            <atom:updated>2019-11-27T03:30:36.315Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Preparing TIFF images for image translation with Pix2Pix]]></title>
            <link>https://medium.com/data-science/preparing-tiff-images-for-image-translation-with-pix2pix-f56fa1e937cb?source=rss-500dff1f8d3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/f56fa1e937cb</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[generative-adversarial]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Haohui]]></dc:creator>
            <pubDate>Fri, 22 Nov 2019 15:59:34 GMT</pubDate>
            <atom:updated>2019-11-26T11:14:56.044Z</atom:updated>
            <content:encoded><![CDATA[<h4>Your guide to getting started with pix2pix using tiff images</h4><p>Generative Adversarial Networks (GANs) have gained a lot of attention recently for the impressive feats they have achieved, ranging from image generation, image translation, style transfer, image colorization and so on. In particular, pix2pix, developed by Isola et al., has become very popular as a Conditional Generative Adversarial Network (CGAN), which allows users to generate images based on an input image. Some examples include translating from semantic labelled images to a street scene, daytime photos to nighttime photos, sketches to photos and so on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aZTXGhMpdOGUf4Z60ZpNcA.png" /><figcaption>Image taken from <a href="https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix">https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix</a></figcaption></figure><p>All these are very impressive, but currently, pix2pix is catered mostly to PNG and JPG images. This is unfortunate as some tasks, for example medical imaging, use TIFF images which are lossless, whereas standard JPEG files are lossless, hence capturing more accurate details. TIFF images have float values whereas PNG and JPG images have integer values, so it is important to preserve this precision when implementing pix2pix.</p><p>Furthermore, CGANs require images to be scaled to the range of [-1, 1] for more stable training. However, normalization isn’t so straight forward by simply using an out-of-the-box function because TIFF images, unlike standard PNG and JPG images that have pixel values from 0–255, can have varying values. In my case, my TIFF images had values ranging from 0–1200!</p><p>Keeping these points in mind, I will detail how you can apply pix2pix to your TIFF images successfuly.</p><h4>Understanding your data</h4><p>First off, find the number of channels your image has. RGB images have 3 channels, whereas grayscale images only have 1. For TIFF images, they can come in varying numbers of channels, so it is important to understand your image data before using pix2pix, because the later decisions you make in coding the architecture will depend on this. Use the following code snippet to find the number of channels your image has:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c07e48e9cf6297c9e9178dba8c0af39e/href">https://medium.com/media/c07e48e9cf6297c9e9178dba8c0af39e/href</a></iframe><h4>Preparing your dataset</h4><p>Now that you have a better understanding of your dataset, you have to prepare your dataset. Pix2pix is unique because it requires paired images across the 2 domains which are exactly identical to each other. Hence, in the official <a href="https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix">PyTorch implementation</a>, the images have to be combined together side by side to produce a composite image of width * 2 x height. Keeping in mind the need to preserve the precision of the values of the TIFF file, I used the PIL library to open the images and then used numpy to concatenate the two images together.</p><p>First, prepare your dataset in the following format: folderA should contain the subfolders train, validation (if any), and test (if any) containing all the images in domain A, while folderB should contain the subfolders train, validation (if any), and test (if any) containing all the images in domain B. Take care to make sure the images in folderA and folderB have the same dimensions and have the same name. Then, use the following code below to generate your concatenated images. The destination path (dest_path) is the directory that you want your concatenated images to be saved. The resulting name will be the same as the original name in folderA and folderB.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1bd5c83782477dcb516d70dd2dd1e0ca/href">https://medium.com/media/1bd5c83782477dcb516d70dd2dd1e0ca/href</a></iframe><h4>Normalizing your Data</h4><p>Pix2pix uses the tanh activation function for the output layer of the generator model, which produces images with pixel values in the range of [-1, 1]. Hence it is important that the discriminator receives real images also in the same range as that generated by the generator model. However, out-of-the-box solutions do not work because they assume the pixel values are in the range of 0–255, as is the case for normal PNG and JPG images. This doesn’t hold for TIFF images, as the range of pixel values vary for each image, so it is important to first find the minimum and maximum for the image before dividing. The code snippet below allows you to scale images based on the original pixel values:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3846767bded809ec92eea5cd8c51d43a/href">https://medium.com/media/3846767bded809ec92eea5cd8c51d43a/href</a></iframe><h4>Wrapping up</h4><p>So that’s it! You have prepared your tiff dataset and are ready to implement the pix2pix code, be it with the official <a href="https://github.com/phillipi/pix2pix">Torch implementation</a>, <a href="https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix">PyTorch</a>, <a href="https://www.tensorflow.org/tutorials/generative/pix2pix">Tensorflow</a> and so on. If you face any issues, let me know in the comments and I will try my best to help you.</p><p>This article has also been published <a href="https://machinelearningtutorials.weebly.com/home/preparing-tiff-images-for-image-translation-with-pix2pix">here</a> in my blog.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f56fa1e937cb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/preparing-tiff-images-for-image-translation-with-pix2pix-f56fa1e937cb">Preparing TIFF images for image translation with Pix2Pix</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[Upgrade your memory on Google Colab FOR FREE]]></title>
            <link>https://medium.com/data-science/upgrade-your-memory-on-google-colab-for-free-1b8b18e8791d?source=rss-500dff1f8d3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b8b18e8791d</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Haohui]]></dc:creator>
            <pubDate>Tue, 19 Nov 2019 04:16:26 GMT</pubDate>
            <atom:updated>2019-11-26T11:00:48.378Z</atom:updated>
            <content:encoded><![CDATA[<h4>Increase the 12GB limit to 25GB</h4><p>Google Colab has truly been a godsend, providing everyone with free GPU resources for their deep learning projects. However, sometimes I do find the memory to be lacking. But don’t worry, because it is actually possible to increase the memory on Google Colab FOR FREE and turbocharge your machine learning projects! Each user is currently allocated 12 GB of RAM, but this is not a fixed limit — you can upgrade it to 25GB. Seems like the saying that “there is no free lunch in this world” doesn’t hold in this case…</p><p>So without further delay, I will introduce how you can get a free upgrade from the current 12GB to 25GB. This process is actually very simple and only requires 3 lines of code! After connecting to a runtime, just type the following snippet:</p><pre>a = []<br>while(1):<br>    a.append(‘1’)</pre><p><em>Credits to klazaj on </em><a href="https://github.com/googlecolab/colabtools/issues/253#issuecomment-551056637"><em>Github</em></a><em> for this code snippet!</em></p><p>That’s it — how simple! Simply execute the block of code and sit back and wait. After a minute or so, you will get a notification from Colab saying “Your session crashed.” (Trust me, you will actually be happy for once seeing this message).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nrkZU41Uyf12mEWEtg-G3g.png" /><figcaption>You will receive a message on the bottom left side of your screen saying your session has crashed</figcaption></figure><p>This will be followed by a screen asking if you would like to switch to a high-RAM runtime.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s_vQL_R1NFZvDDD49Cyfsw.png" /><figcaption>Yes, definitely more RAM please!</figcaption></figure><p>Click yes, and you will be rewarded with 25GB of RAM. How wonderful!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4gXii-KFv4H70ngwFiTR7w.png" /><figcaption>Notice the new 25.51 GB limit. (And yes, Corgi Mode!)</figcaption></figure><p>Of course, let’s all be responsible and use this extra memory that Google has kindly provided for us well. I am extremely grateful to Google for providing us this free platform to run our machine learning and deep learning projects. I have benefited extremely from this free service and will definitely be eternally grateful!</p><p>That’s it for this post. Here’s to wishing everyone great success in their machine learning endeavors!</p><p>This article has also been published <a href="https://machinelearningtutorials.weebly.com/home/upgrade-your-memory-on-google-colab-for-free">here</a> in my blog.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b8b18e8791d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/upgrade-your-memory-on-google-colab-for-free-1b8b18e8791d">Upgrade your memory on Google Colab FOR FREE</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>
    </channel>
</rss>