<?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 Greg Chu on Medium]]></title>
        <description><![CDATA[Stories by Greg Chu on Medium]]></description>
        <link>https://medium.com/@gregchu?source=rss-846102b4e1ff------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*w_-V63jqfGivEmucXxxAmQ.jpeg</url>
            <title>Stories by Greg Chu on Medium</title>
            <link>https://medium.com/@gregchu?source=rss-846102b4e1ff------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 11:52:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gregchu/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[Representation Learning: Understanding the Fundamentals]]></title>
            <link>https://medium.com/deeplearningsandbox/contrastive-learning-part-1-understanding-the-fundamentals-988564b66bad?source=rss-846102b4e1ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/988564b66bad</guid>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[contrastive-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <dc:creator><![CDATA[Greg Chu]]></dc:creator>
            <pubDate>Thu, 30 Oct 2025 02:53:56 GMT</pubDate>
            <atom:updated>2025-11-15T19:54:37.995Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Context: </strong>Representation learning solves a fundamental challenge in machine learning: learning meaningful representations without extensive labeled data. Instead of requiring explicit labels for every example, it learns by understanding relationships. A specific form of representation learning, contrastive learning, is about learning what’s similar and what’s different.</p><p><strong>Goal: </strong>Learn an embedding function that maps data to a latent space where similar items cluster together and dissimilar items spread apart.</p><p><strong>Usefulness:</strong></p><ul><li><strong><em>Semantic retrieval:</em></strong> powers search, recommendations, retrieval augmented generation (RAG) systems, etc., by finding semantically similar items through approximate nearest-neighbor search in embedding space</li><li><strong><em>Few-shot learning:</em></strong> classifies new categories with only a few examples per class by comparing embeddings in learned metric space. Critical for:<br>- Rare disease diagnosis (limited patient data)<br>- New product categorization (cold start problem)<br>- Personalized recommendations (new users, niche/dynamic preferences)<br>- High-cardinality problems (thousands of classes)</li></ul><p><strong>Key Factor: </strong><em>Loss Function</em></p><p>What makes contrastive learning unique is the loss function. While traditional supervised learning uses cross-entropy loss on class labels, contrastive learning uses losses that directly optimize the embedding space geometry. These loss functions push positive pairs (similar items) closer together and negative pairs (dissimilar items) further apart. We’ll explore two common approaches:</p><ol><li><strong>Triplet Loss:</strong> Encourages positives to be closer than negatives by a margin</li><li><strong>InfoNCE:</strong> Encourages positives to be closer than a collection of negatives</li></ol><h3>Application: Toy Example</h3><h4>Dataset</h4><p>Randomly generated feature vectors representing three classes:</p><pre>NUM_SAMPLES = 300<br>EMBEDDING_SIZE = 64<br>NUM_CLASSES = 3<br><br>data = torch.randn(NUM_SAMPLES, EMBEDDING_SIZE) # range = [-1,1]<br>labels = torch.randint(0, NUM_CLASSES, (NUM_SAMPLES,))</pre><p><strong>Initial State:</strong> Before training, these vectors are randomly distributed with no meaningful structure. If we visualize them with <a href="https://en.wikipedia.org/wiki/T-distributed_stochastic_neighbor_embedding">t-SNE</a>, we see an unorganized blob with overlapping classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*i_H4JseJFYP5QRUX.png" /><figcaption>t-SNE embeddings with 3 classes</figcaption></figure><h3>Embedding Network</h3><p>We’ll use a simple two-layer MLP that maps inputs through a hidden layer (2x the input size) to the embedding space, with L2 normalization at the output:</p><pre>class ContrastiveEncoder(nn.Module):<br>    def __init__(self, input_size, embedding_size):<br>        super().__init__()<br>        self.model = nn.Sequential(<br>            nn.Linear(input_size, input_size * 2),<br>            nn.ReLU(),<br>            nn.BatchNorm1d(input_size * 2),<br>            nn.Linear(input_size * 2, embedding_size)<br>        )<br>    <br>    def forward(self, x):<br>        x = self.model(x)<br>        x = F.normalize(x, p=2, dim=1)<br>        return x</pre><p><strong>L2 Normalization:</strong> Normalizing embeddings to unit length stabilizes distance computations and focuses learning on angular relationships rather than magnitude. This makes the model more robust and ensures all samples live on the unit hypersphere.</p><h4>Triplet Loss (<a href="https://arxiv.org/abs/1503.03832">Schroff et al., 2015</a>)</h4><pre>loss = max(0, dist(anchor, positive) - dist(anchor, negative) + margin)</pre><p><strong>Intuition:</strong> For each training sample (anchor), we:</p><ol><li>Compute distance to a similar sample (positive)</li><li>Compute distance to a dissimilar sample (negative)</li><li>Optimize so that: dist(anchor, positive) + margin &lt; dist(anchor, negative)</li></ol><p>The margin ensures a minimum separation between positives and negatives, adding stability to training.</p><p><strong>max(0, …) operator:</strong></p><ul><li>Intuition: If the negative is already far enough away, stop optimizing that triplet (loss becomes zero)</li><li>Implementation: Uses nn.ReLU or F.relu</li><li>Effect: Focuses training on “hard” examples where the margin is violated</li></ul><p><strong>margin hyperparameter:</strong></p><ul><li>Intuition: Minimum distance gap between negatives and positives</li><li>Common values: 0.2–1.0, with 0.5 being a popular default</li><li>Fine-grained tasks (facial recognition): 0.2–0.3</li><li>Coarse-grained tasks (product categories): 0.8–1.0</li><li>Tuning priority: Optimize learning rate, batch size, and negative mining strategy before margin</li></ul><p><strong>Distance Metric:</strong></p><ul><li>Typically uses Euclidean (L2) distance</li><li>Alternative: Cosine distance for normalized embeddings</li></ul><pre>class TripletLoss(nn.Module):<br>    def __init__(self, margin=1.0):<br>        super().__init__()<br>        self.margin = margin<br><br>    def forward(self, anchor, positive, negative):<br>        pos_dist = F.pairwise_distance(anchor, positive)<br>        neg_dist = F.pairwise_distance(anchor, negative)<br>        losses = F.relu(pos_dist - neg_dist + self.margin)<br>        return losses.mean()</pre><p>Note: PyTorch implementation <a href="https://docs.pytorch.org/docs/stable/generated/torch.nn.TripletMarginLoss.html">here</a></p><p><strong>Configuration:</strong></p><pre>num_epochs = 100<br>batch_size = 32<br>learning_rate = 1e-3<br>optimizer = Adam<br>margin = 1.0</pre><p><strong>Results: </strong>After training, the t-SNE visualization shows clear separation between classes. Each class forms a distinct cluster, with minimal overlap. The learned embedding space captures semantic similarity: samples from the same class are grouped together, while different classes are pushed apart by at least the margin distance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uwT8Bf_6tbH-L2Gh.png" /><figcaption>t-SNE plot of samples after applying learned embedding function w/ Triplet loss</figcaption></figure><p><strong>Key observation:</strong> Triplet loss creates well-separated clusters but only uses 1 negative per step (inefficient). This motivates InfoNCE loss: a more efficient approach that handles multiple negatives simultaneously (rather than one at a time).</p><h4>InfoNCE Loss (<a href="https://arxiv.org/abs/1807.03748">Oord et. al., 2018</a>)</h4><pre>loss = -log(exp(sim(anchor, positive) / τ) / Σₖ exp(sim(anchor, candidate_k) / τ))</pre><p>Where:</p><ul><li>sim(·,·) is typically cosine similarity</li><li>τ (tau) is the temperature parameter</li><li>The sum is over all N candidates (1 positive + N-1 negatives)</li></ul><p><strong>Intuition:</strong> This is cross-entropy loss applied to pairwise similarity scores instead of logits (as in the classification case), where the correct match (positive) is treated as the true class<em>.</em> We’re making the positive sample stand out among all candidates by maximizing its probability in a softmax distribution.</p><p><strong>Negative Sampling Strategies:</strong></p><ul><li><strong>Explicit negative sampling:<br>- </strong>Sample specific negatives per anchor (e.g. hard negative mining)<br>- Flexible, but slower and less scalable</li><li><strong>In-batch negatives (popularized by </strong><a href="https://arxiv.org/abs/2002.05709"><strong>SimCLR</strong></a><strong>):<br>- </strong>Every other sample in the batch is treated as a negative<br>- Efficient because you reuse batch data<br>- May introduce false negatives¹ (SimCLR mitigates w/ large batch sizes)</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplayer.vimeo.com%2Fvideo%2F1131908564%3Fapp_id%3D122963&amp;dntp=1&amp;display_name=Vimeo&amp;url=https%3A%2F%2Fvimeo.com%2F1131908564&amp;image=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F2075982090-78697fad590438051a09c4b42654aac4d7589e5bbebf686fa74afd6d06a130f4-d_640%3Fregion%3Dus&amp;type=text%2Fhtml&amp;schema=vimeo" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/fee3e72c9ce111ac5b55332887f54302/href">https://medium.com/media/fee3e72c9ce111ac5b55332887f54302/href</a></iframe><ul><li><strong>Memory bank (</strong><a href="https://arxiv.org/abs/1911.05722"><strong>MoCo v1</strong></a><strong>/</strong><a href="https://arxiv.org/abs/2003.04297"><strong>v2</strong></a><strong>):<br>- </strong>Maintains a queue of previous embeddings as negatives<br>- Allows thousands of negatives even with small batch sizes<br>- Reduces false negatives somewhat but adds complexity</li></ul><p><strong>Temperature Parameter</strong></p><ul><li>Controls the “sharpness” of the probability distribution:</li><li>Low temperature (0.05–0.1):<br>- Creates sharper, more peaked distributions<br>- Forces stronger confidence in the positive<br>- Higher penalties on hard negatives<br>- Faster convergence but risks overfitting</li><li>High temperature (0.3–0.5):<br>- Creates smoother, more uniform distributions<br>- More forgiving of hard negatives<br>- Slower convergence but better generalization<br>- Useful when data has noise or ambiguous labels</li><li>Common values:<br>- SimCLR: 0.07<br>- MoCo: 0.2<br>- CLIP: 0.07<br>- Common starting point: 0.1</li></ul><pre>class InfoNCELoss(nn.Module):<br>    def __init__(self, temperature=0.1):<br>        super(InfoNCELoss, self).__init__()<br>        self.temperature = temperature<br><br>    def forward(self, anchor, positive):<br>        &quot;&quot;&quot;<br>        Args:<br>            anchor: (batch_size, embedding_dim)<br>            positive: (batch_size, embedding_dim) - positive samples<br>        For each anchor[i], positive[i] is the correct match (label=i).<br>        All other samples in the batch serve as negatives.<br>        &quot;&quot;&quot;<br>        batch_size = anchor.shape[0]<br><br>        # Normalize embeddings for cosine similarity<br>        anchor = F.normalize(anchor, p=2, dim=-1)<br>        positive = F.normalize(positive, p=2, dim=-1)<br><br>        # Compute similarity matrix: (batch_size, batch_size)<br>        similarity_matrix = torch.matmul(anchor, positive.T) # If using a momentum encoder (MoCo), positive embeddings come from a separate encoder<br>        similarity_matrix /= self.temperature<br><br>        # Labels: anchor[i] should match positive[i] at index i<br>        labels = torch.arange(batch_size, device=anchor.device)<br><br>        # Cross entropy: -log(exp(sim[i,i]) / sum_j(exp(sim[i,j])))<br>        return F.cross_entropy(similarity_matrix, labels)</pre><p><strong>Configuration:</strong></p><pre>num_epochs = 100<br>batch_size = 32<br>learning_rate = 1e-3<br>optimizer = Adam<br>temperature = 0.1</pre><p><strong>Results: </strong>For this toy dataset, Triplet and InfoNCE losses perform similarly, showing comparable clustering in t-SNE. As we scale to real-world problems (e.g., millions of samples across thousands of classes), InfoNCE’s ability to efficiently leverage multiple negatives simultaneously becomes essential.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-dqNP8nN4ZVJRiQ3.png" /><figcaption>t-SNE plot of samples after applying learned embedding function w/ InfoNCE loss</figcaption></figure><p>In Part 2, we’ll explore how these foundational ideas power modern image contrastive methods like <a href="https://arxiv.org/abs/2002.05709">SimCLR</a>, <a href="https://arxiv.org/abs/1911.05722">MoCo</a>, and <a href="https://arxiv.org/pdf/2006.07733">BYOL</a>.</p><p>¹ When two semantically similar samples (but with different labels) end up in the same batch, one gets treated as a negative for the other, creating conflicting signals.</p><p><strong>References</strong></p><ul><li>Schroff <em>et al.</em> (2015). <em>FaceNet: A Unified Embedding for Face Recognition and Clustering.</em> <a href="https://arxiv.org/abs/1503.03832">arXiv:1503.03832</a></li><li>Chen <em>et al.</em> (2020). <em>A Simple Framework for Contrastive Learning of Visual Representations.</em> <a href="https://arxiv.org/abs/2002.05709">arXiv:2002.05709</a></li><li>He <em>et al.</em> (2020). <em>Momentum Contrast for Unsupervised Visual Representation Learning.</em> <a href="https://arxiv.org/abs/1911.05722">arXiv:1911.05722</a></li><li>Chen <em>et al.</em> (2020). <em>Improved Baselines with Momentum Contrastive Learning.</em> <a href="https://arxiv.org/abs/2003.04297">arXiv:2003.04297</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=988564b66bad" width="1" height="1" alt=""><hr><p><a href="https://medium.com/deeplearningsandbox/contrastive-learning-part-1-understanding-the-fundamentals-988564b66bad">Representation Learning: Understanding the Fundamentals</a> was originally published in <a href="https://medium.com/deeplearningsandbox">Deep Learning Sandbox</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How GumGum Serves its CV at Scale]]></title>
            <link>https://medium.com/gumgum-tech/how-gumgum-serves-its-cv-at-scale-e5db450c5011?source=rss-846102b4e1ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5db450c5011</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Greg Chu]]></dc:creator>
            <pubDate>Wed, 14 Aug 2019 21:44:10 GMT</pubDate>
            <atom:updated>2019-08-14T21:44:10.938Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L__IgRfDaSydneTfQMIYnQ.png" /><figcaption>Example frame with detections and confidences drawn</figcaption></figure><p>On May 28, 2019, myself (Greg Chu) and Corey Gale presented a talk titled <em>“How GumGum Serves its CV at Scale”</em> at the <a href="https://www.meetup.com/Los-Angeles-Computer-Vision-Meetup/events/261362669/">LA Computer Vision Meetup</a> in GumGum’s Santa Monica office.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplayer.vimeo.com%2Fvideo%2F340334090%3Fapp_id%3D122963&amp;dntp=1&amp;url=https%3A%2F%2Fvimeo.com%2F340334090&amp;image=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F788636054_1280.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=vimeo" width="1920" height="1050" frameborder="0" scrolling="no"><a href="https://medium.com/media/35b427cfff136fff09c908f380575cbc/href">https://medium.com/media/35b427cfff136fff09c908f380575cbc/href</a></iframe><h4>Abstract:</h4><h4>Abstract:</h4><p>Given the rapidly growing utility of computer vision applications, how do we deploy these services in high-traffic production environments to generate business value? Here we present GumGum’s approach to building infrastructure for serving computer vision models in the cloud. We’ll also demo code for building a car make-model detection server.</p><h4>Topics:</h4><ul><li><a href="https://github.com/gumgum/multivitamin/">Multivitamin</a>: an open-sourced Python framework for serving library-agnostic machine learning models</li><li>Containerization: packaging everything you need into a single portable artifact</li><li>CI/CD: automating builds and releases with Drone CI</li><li>Custom auto-scaling: using AWS Lambda to scale our infrastructure based on business metrics</li></ul><h4>Speakers:</h4><p><a href="https://www.linkedin.com/in/greghchu/">Greg Chu</a> is a Senior Computer Vision Scientist at GumGum, where he works on both the training and large-scale deployment of object detection and recognition models. These models are applied within GumGum’s products for contextual advertising and sports sponsorship analytics. Greg has a background in biomedical physics. In his Ph.D research he developed tumor segmentation models to assess the clinical progression of patients in FDA clinical drug trials.</p><p><a href="https://www.linkedin.com/in/coreyjgale/">Corey Gale</a> is a Senior DevOps Engineer at GumGum. He works on automating cloud infrastructure for highly-scalable systems using open-source technologies. With his background in Robotics Engineering, Corey is a believer that through automation, anything is possible. He is also obsessed with process (measure all the things!), cost-reduction and entrepreneurship (Corey actually created a food delivery app in 2012, well before they became mainstream).</p><p>We’re always looking for new talent! <a href="https://gumgum.com/careers">View jobs</a>.</p><p>Follow us: <a href="https://www.facebook.com/gumguminc">Facebook</a> | <a href="https://twitter.com/gumgum">Twitter</a> | | <a href="https://www.linkedin.com/company/167379/">Linkedin</a> | <a href="https://www.instagram.com/gumguminc/">Instagram</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5db450c5011" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gumgum-tech/how-gumgum-serves-its-cv-at-scale-e5db450c5011">How GumGum Serves its CV at Scale</a> was originally published in <a href="https://medium.com/gumgum-tech">GumGum Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use transfer learning and fine-tuning in Keras and Tensorflow to build an image recognition…]]></title>
            <link>https://medium.com/deeplearningsandbox/how-to-use-transfer-learning-and-fine-tuning-in-keras-and-tensorflow-to-build-an-image-recognition-94b0b02444f2?source=rss-846102b4e1ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/94b0b02444f2</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Greg Chu]]></dc:creator>
            <pubDate>Mon, 01 May 2017 17:32:35 GMT</pubDate>
            <atom:updated>2019-06-06T08:02:50.021Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to use transfer learning and fine-tuning in Keras and Tensorflow to build an image recognition system and classify (almost) any object</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cIVP1TzkH4lI31pEARdUOA.png" /><figcaption>Example images from the <a href="http://mmlab.ie.cuhk.edu.hk/datasets/comp_cars/index.html">CompCars</a> dataset (163 car makes, 1713 car models)</figcaption></figure><blockquote><em>Go straight to the code on GitHub </em><a href="https://github.com/DeepLearningSandbox/DeepLearningSandbox/tree/master/transfer_learning"><em>here</em></a><em>!</em></blockquote><p>In the last post, I covered how to use Keras to recognize any of the 1000 object categories in the ImageNet visual recognition challenge. More often than not, however, the categories we are interested in predicting are not in that list.</p><blockquote><strong><em>So what do we do if want to classify between different models of sunglasses? or shoes? or facial expressions? or different models of cars? or different types of lung disease in X-ray images?</em></strong></blockquote><p>In this post, I will show you how to use transfer learning and fine-tuning to identify any customizable object categories! To recapitulate, here is the blog post series we’ll be following:</p><ol><li><a href="https://deeplearningsandbox.com/how-to-build-an-image-recognition-system-using-keras-and-tensorflow-for-a-1000-everyday-object-559856e04699">Build an image recognition system for a 1000 everyday object categories (ImageNet ILSVRC) using Keras and TensorFlow</a></li><li><strong>Build an image recognition system for any customizable object categories using transfer learning and fine-tuning in Keras and TensorFlow (this post)</strong></li><li>Build a real-time bounding-box object detection system for hundreds of everyday object categories (PASCAL VOC, COCO)</li><li>Build a web service for any image recognition or object detection system</li></ol><h3>Why use transfer learning/fine tuning?</h3><p>It’s well known that convolutional networks require significant amounts of data and resources to train. For example, the ImageNet ILSVRC model was trained on 1.2 million images over the period of 2–3 weeks across multiple GPUs.</p><blockquote><strong>It has become the norm, not the exception, for researchers and practitioners alike to use transfer learning and fine-tuning, that is, transferring the network weights trained on a previous task like ImageNet to a new task.</strong></blockquote><p>And it does astoundingly well! <a href="https://arxiv.org/pdf/1403.6382.pdf">Razavian et al (2014)</a> showed that by simply using the features extracted using the weights from an ImageNet ILSVRC trained model, they achieved state-of-the-art or near state-of-the-art performance on a large variety of computer vision tasks.</p><p>There are two approaches we can take:</p><ol><li><strong>Transfer learning: </strong>take a ConvNet that has been pre-trained on ImageNet, remove the last fully-connected layer, then treat the rest of the ConvNet as a feature extractor for the new dataset. Once you extract the features for all images, train a classifier for the new dataset.</li><li><strong>Fine-tuning</strong>: replace and retrain the classifier on top of the ConvNet, and also fine-tune the weights of the pre-trained network via backpropagation.</li></ol><h4>Which to use?</h4><p>There are two main factors that will affect your choice of approach:</p><ol><li>Your dataset size</li><li>Similarity of your dataset to the pre-trained dataset (typically ImageNet)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d6iwmZTr9OY4TtjJW81_Ww.png" /><figcaption>Taken from <a href="http://cs231n.github.io/">http://cs231n.github.io/</a></figcaption></figure><p>*you should also experiment with training from scratch as well.</p><p>The figure above and the bullets below describe some general advice for when to choose which approach.</p><ul><li><strong>Similar &amp; small dataset: </strong>avoid overfitting by not fine-tuning the weights on a small dataset, and use extracted features from the highest levels of the ConvNet to leverage dataset similarity.</li><li><strong>Different &amp; small dataset:</strong> avoid overfitting by not fine-tuning the weights on a small dataset, and use extracted features from lower levels of the ConvNet which are more generalizable.</li><li><strong>Similar &amp; large dataset:</strong> with a large dataset we can fine-tune the weights with less of a chance to overfit the training data.</li><li><strong>Different &amp; large dataset:</strong> with a large dataset we again can fine-tune the weights with less of a chance to overfit.</li></ul><h4>Data augmentation</h4><p>A powerful and common tool for increasing the dataset size and model generalizability is <em>data augmentation. </em>In fact, <strong>every competition winning ConvNet employs the use of data augmentation</strong>. Essentially, data augmentation is the process of artificially increasing the size of your dataset via transformations.</p><p>Most deep learning libraries have ready-made functions for typical transformations. For our image recognition system, the task you have is to decide <em>which</em> transformations make sense for your data (for example, X-ray images should probably not be rotated by more than 45 degrees because that would mean there was an error in the image acquisition step).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*tBm-LSuCu3aYKsGA4XEPYg.png" /><figcaption>Data augmentation via horizontal flipping and random cropping</figcaption></figure><p><strong>Example transformations: </strong>Pixel color jitter, rotation, shearing, random cropping, horizontal flipping, stretching, lens correction.</p><h3>Transfer learning and fine-tuning implementation</h3><p><em>Go straight to the code on GitHub </em><a href="https://github.com/DeepLearningSandbox/DeepLearningSandbox/tree/master/transfer_learning"><em>here</em></a><em>!</em></p><h4>Data preparation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-5uYpem4AWxs-CVFmRwflQ.png" /><figcaption>Sample images from Kaggle’s Cat vs Dog dataset</figcaption></figure><p>We’ll use <a href="https://www.kaggle.com/c/dogs-vs-cats/data">Kaggle’s Dogs vs Cats dataset</a> as our example, and setup our data with a training directory and a validation directory in this manner:</p><pre>train_dir/<br>  dog/<br>  cat/<br>val_dir/<br>  dog/<br>  cat/</pre><h4>Implementation</h4><p>Let’s start by preparing our data generators:</p><pre>train_datagen =  ImageDataGenerator(<br>    preprocessing_function=preprocess_input,<br>    rotation_range=30,<br>    width_shift_range=0.2,<br>    height_shift_range=0.2,<br>    shear_range=0.2,<br>    zoom_range=0.2,<br>    horizontal_flip=True<br>)</pre><pre>test_datagen = ImageDataGenerator(<br>    preprocessing_function=preprocess_input,<br>    rotation_range=30,<br>    width_shift_range=0.2,<br>    height_shift_range=0.2,<br>    shear_range=0.2,<br>    zoom_range=0.2,<br>    horizontal_flip=True<br>)</pre><pre>train_generator = train_datagen.flow_from_directory(<br>  args.train_dir,<br>  target_size=(IM_WIDTH, IM_HEIGHT),<br>  batch_size=batch_size,<br>)</pre><pre>validation_generator = test_datagen.flow_from_directory(<br>  args.val_dir,<br>  target_size=(IM_WIDTH, IM_HEIGHT),<br>  batch_size=batch_size,<br>)</pre><p>Recall from our previous <a href="https://deeplearningsandbox.com/how-to-build-an-image-recognition-system-using-keras-and-tensorflow-for-a-1000-everyday-object-559856e04699">blog post on image recognition</a> the importance of the preprocessing step. This is set by preprocessing_function = preprocess_input where preprocess_input is from the keras.applications.inception_v3 module.</p><p>The rotation, shifting, shearing, zooming, and flipping parameters signal ranges for their respective data augmentation transformations.</p><p>Next, we’ll instantiate the InceptionV3 network from the keras.applications module.</p><p>base_model = InceptionV3(weights=&#39;imagenet&#39;, include_top=False)</p><p>We use the flag include_top=False to leave out the weights of the last fully connected layer since that is specific to the ImageNet competition, from which the weights were previously trained. We’ll add and initialize a new last layer:</p><pre>def add_new_last_layer(base_model, nb_classes):<br>  &quot;&quot;&quot;Add last layer to the convnet<br>  Args:<br>    base_model: keras model excluding top<br>    nb_classes: # of classes<br>  Returns:<br>    new keras model with last layer<br>  &quot;&quot;&quot;<br>  x = base_model.output<br>  x = GlobalAveragePooling2D()(x)<br>  x = Dense(FC_SIZE, activation=&#39;relu&#39;)(x) <br>  predictions = Dense(nb_classes, activation=&#39;softmax&#39;)(x) <br>  model = Model(input=base_model.input, output=predictions)<br>  return model</pre><p>GlobalAveragePooling2D converts the MxNxC tensor output into a 1xC tensor where C is the # of channels.</p><p>Then we add on a fully-connected Dense layer of size 1024, and a softmax function on the output to squeeze the values between [0,1].</p><p>In this program, I’ll demonstrate both transfer learning <em>and </em>fine-tuning. You can use either or both if you like.</p><ol><li><strong>Transfer learning: </strong>freeze all but the penultimate layer and re-train the last Dense layer</li><li><strong>Fine-tuning: </strong>un-freeze the lower convolutional layers and retrain more layers</li></ol><p><strong><em>Doing both, in that order, will ensure a more stable and consistent training.</em></strong> This is because the large gradient updates triggered by randomly initialized weights could wreck the learned weights in the convolutional base if not frozen. Once the last layer has stabilized (transfer learning), then we move onto retraining more layers (fine-tuning).</p><h4>Transfer learning</h4><pre>def setup_to_transfer_learn(model, base_model):<br>  &quot;&quot;&quot;Freeze all layers and compile the model&quot;&quot;&quot;<br>  for layer in base_model.layers:<br>    layer.trainable = False<br>  model.compile(optimizer=&#39;rmsprop&#39;,    <br>                loss=&#39;categorical_crossentropy&#39;, <br>                metrics=[&#39;accuracy&#39;])</pre><h4>Fine-tune</h4><pre>def setup_to_finetune(model):<br>   &quot;&quot;&quot;Freeze the bottom NB_IV3_LAYERS and retrain the remaining top <br>      layers.<br>   note: NB_IV3_LAYERS corresponds to the top 2 inception blocks in <br>         the inceptionv3 architecture<br>   Args:<br>     model: keras model<br>   &quot;&quot;&quot;<br>   for layer in model.layers[:NB_IV3_LAYERS_TO_FREEZE]:<br>      layer.trainable = False<br>   for layer in model.layers[NB_IV3_LAYERS_TO_FREEZE:]:<br>      layer.trainable = True<br>   model.compile(optimizer=SGD(lr=<strong>0.0001</strong>, momentum=0.9),   <br>                 loss=&#39;categorical_crossentropy&#39;)</pre><p>When fine-tuning, it’s important to lower your learning rate relative to the rate that was used when training from scratch (lr=0.0001), otherwise, the optimization could destabilize and the loss diverge.</p><h4>Training</h4><p>Now we’re all set for training. Use fit_generator for both transfer learning and fine-tuning.</p><pre>history = model.fit_generator(<br>  train_generator,<br>  samples_per_epoch=nb_train_samples,<br>  nb_epoch=nb_epoch,<br>  validation_data=validation_generator,<br>  nb_val_samples=nb_val_samples,<br>  class_weight=&#39;auto&#39;<br>)</pre><pre>model.save(args.output_model_file)</pre><p>We’ll use an Amazon EC2 g2.2xlarge instance for training. If you’re unfamiliar with AWS, check out this <a href="http://cs231n.github.io/aws-tutorial/">tutorial</a> (instead of using their prescribed AMI, search the community AMIs for “deep learning” — for this post, I used ami-638c1eo3in US-West-Oregon).</p><p>We can plot the training accuracies and loss using the history object</p><pre>def plot_training(history):<br>  acc = history.history[&#39;acc&#39;]<br>  val_acc = history.history[&#39;val_acc&#39;]<br>  loss = history.history[&#39;loss&#39;]<br>  val_loss = history.history[&#39;val_loss&#39;]<br>  epochs = range(len(acc))<br>  <br>  plt.plot(epochs, acc, &#39;r.&#39;)<br>  plt.plot(epochs, val_acc, &#39;r&#39;)<br>  plt.title(&#39;Training and validation accuracy&#39;)<br>  <br>  plt.figure()<br>  plt.plot(epochs, loss, &#39;r.&#39;)<br>  plt.plot(epochs, val_loss, &#39;r-&#39;)<br>  plt.title(&#39;Training and validation loss&#39;)</pre><pre>  plt.show()</pre><h4>Prediction</h4><p>Now that we have a saved keras.model we can modify the same predict() function we wrote in the <a href="https://deeplearningsandbox.com/how-to-build-an-image-recognition-system-using-keras-and-tensorflow-for-a-1000-everyday-object-559856e04699">last blog post</a> to predict the class of a local image file or any file via a web URL. Checkout the <a href="https://github.com/DeepLearningSandbox/DeepLearningSandbox/tree/master/transfer_learning">github</a> for the full program.</p><pre>python predict.py --image dog.001.jpg --model dc.model<br>python predict.py --image_url <a href="https://goo.gl/Xws7Tp">https://goo.gl/Xws7Tp</a> --model dc.model</pre><h3>We’re done!</h3><p>As an example, I trained a model on the <a href="https://www.kaggle.com/c/dogs-vs-cats/data">dogs-vs-cats dataset</a> using 24000 images for training and 1000 images for validation for 2 epochs. Even after only 2 epochs, the performance is pretty high:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TBG9lk83FuAMz6it-61CHg.png" /><figcaption>Metrics log after 2 epochs</figcaption></figure><blockquote>Download the trained model <a href="https://drive.google.com/file/d/0B9-cM_0P8MFGRmM1TU14b3ptVGM/view?usp=sharing">here</a>*</blockquote><p>*model compatible with keras==1.2.2</p><h4>Examples</h4><p>python predict.py --image_url <a href="https://goo.gl/Xws7Tp">https://goo.gl/Xws7Tp</a> --model dc.model</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*uKXJ4xjUGWMVtxAa3qoU7A.png" /></figure><p>python predict.py --image_url <a href="https://goo.gl/6TRUol">https://goo.gl/6TRUol</a> --model dc.model</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*mnAzCtbpwIg6APCVH4whyg.png" /></figure><p>Stay tuned for the next post in the series:</p><ol><li><a href="https://deeplearningsandbox.com/how-to-build-an-image-recognition-system-using-keras-and-tensorflow-for-a-1000-everyday-object-559856e04699">Build an image recognition system for a 1000 everyday object categories (ImageNet ILSVRC) using Keras and TensorFlow</a></li><li><strong>Build an image recognition system for any customizable object categories using transfer learning and fine-tuning in Keras and TensorFlow (this post)</strong></li><li>Build a real-time bounding-box object detection system for hundreds of everyday object categories (PASCAL VOC, COCO)</li><li>Build a web service for any image recognition or object detection system</li></ol><p>If you have any questions contact me at greg.ht.chu@gmail.comor message me on <a href="https://www.linkedin.com/in/greghchu/">LinkedIn</a>!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F19b29f%3Fas_embed%3Dtrue&amp;url=https%3A%2F%2Fupscri.be%2F19b29f%2F&amp;image=https%3A%2F%2Fupscri.be%2Fmedia%2Fform.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b8c429f118803c8c7315b244c4cd252/href">https://medium.com/media/0b8c429f118803c8c7315b244c4cd252/href</a></iframe><p>If you enjoyed this, please click the ❤</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*-uDEn7Pm7HRzrXCoyIWiwA.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94b0b02444f2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/deeplearningsandbox/how-to-use-transfer-learning-and-fine-tuning-in-keras-and-tensorflow-to-build-an-image-recognition-94b0b02444f2">How to use transfer learning and fine-tuning in Keras and Tensorflow to build an image recognition…</a> was originally published in <a href="https://medium.com/deeplearningsandbox">Deep Learning Sandbox</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to build an image recognition system using Keras and Tensorflow for a 1000 everyday object…]]></title>
            <link>https://medium.com/deeplearningsandbox/how-to-build-an-image-recognition-system-using-keras-and-tensorflow-for-a-1000-everyday-object-559856e04699?source=rss-846102b4e1ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/559856e04699</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Greg Chu]]></dc:creator>
            <pubDate>Sat, 25 Mar 2017 02:10:06 GMT</pubDate>
            <atom:updated>2018-03-27T05:21:05.644Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to build an image recognition system using Keras and Tensorflow for a 1000 everyday object categories (ImageNet ILSVRC)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*QloCzL8cAjWKXGb1ijwyGw.png" /><figcaption>Image recognition with the top 5 predicted labels and their probabilities (red row denotes the correct answer) <a href="http://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks.pdf">http://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks.pdf</a></figcaption></figure><blockquote>Go straight to the code on <a href="https://github.com/DeepLearningSandbox/DeepLearningSandbox/tree/master/image_recognition">Github</a>.</blockquote><p>In this series of posts, I will show you how to build your own recognition or detection/bounding box prediction web service in just a few lines of code using <a href="http://keras.io/">Keras</a>, <a href="http://tensorflow.org/">TensorFlow</a>, and the python <a href="http://docs.python-requests.org/en/master/">requests</a> library. The post series is as follows:</p><ol><li><strong>Build an image recognition system for a 1000 everyday object categories (ImageNet ILSVRC) using Keras and TensorFlow (this post)</strong></li><li>Build an image recognition system for any customizable object categories using transfer learning and fine-tuning in Keras and TensorFlow</li><li>Build a real-time bounding-box object detection system for hundreds of everyday object categories (PASCAL VOC, COCO)</li><li>Build a web service for any image recognition or object detection system</li></ol><h3>What is it you want to recognize?</h3><p>There are 3 popular academic competitions in the field of computer vision that have been tremendously impactful: <a href="http://www.image-net.org/challenges/LSVRC/">ImageNet ILSVRC</a>, <a href="http://host.robots.ox.ac.uk/pascal/VOC/">PASCAL VOC</a>, and <a href="http://mscoco.org/dataset/#detections-challenge2016">COCO</a> . These competitions have propelled inventions in computer vision research, and many are available for free and unrestricted use. For this post, I will focus on image recognition using ImageNet ILSCVRC.</p><p>Take a look at the <a href="https://gist.github.com/gregchu/134677e041cd78639fea84e3e619415b">the ILSVRC object list</a>. If the particular objects you’re interested in recognizing are one of the 1001 objects in that list, you’re in luck! Here is an excerpt of the list of object categories:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e017104b3dd5ed5be46cb733ce16cfff/href">https://medium.com/media/e017104b3dd5ed5be46cb733ce16cfff/href</a></iframe><p>What if you’re object of interest is not on that list, or is a significantly different setting like medical image analysis? I will cover an extremely valuable approach called transfer learning and fine-tuning in the second post.</p><h3>Image Recognition</h3><p>What is image (or object) recognition? It answers the question: “what objects are depicted in this image?” This could be useful if you would like to tag images based on content, identify what food is on your plate, classify between images containing cancer or non-cancer, and many more applications.</p><h4>Keras and TensorFlow</h4><p><a href="https://keras.io/">Keras</a> is a high-level neural network library that serves as an easy-to-use abstraction layer on top of the numerical computation library <a href="http://tensorflow.org/">TensorFlow</a>. It even provides access via its keras.applications module to ILSVRC competition-winning convolutional network models like ResNet50 (developed by Microsoft Research) and InceptionV3 (developed by Google Research) for free and unrestricted use. To install, follow the instructions at:</p><ul><li>Keras installation: <a href="https://keras.io/#installation">https://keras.io/#installation</a></li><li>TensorFlow installation: <a href="https://www.tensorflow.org/install/">https://www.tensorflow.org/install/</a></li></ul><h3>Implementation</h3><p><em>To go straight to the full program, check out the </em><a href="https://github.com/DeepLearningSandbox/DeepLearningSandbox/tree/master/image_recognition"><em>github</em></a><em>.</em></p><p>Our end goal is to write a small python program with argument options of either 1. a path to a local file or 2. a URL to an image. Here is the example usage using a photo of an African elephant.</p><pre>1. python classify.py --image African_Bush_Elephant.jpg<br>2. python classify.py --image_url <a href="http://i.imgur.com/wpxMwsR.jpg">http://i.imgur.com/wpxMwsR.jpg</a></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*sSVTQaSTMti6ZcJRcsnSbA.jpeg" /><figcaption><a href="https://upload.wikimedia.org/wikipedia/commons/3/37/African_Bush_Elephant.jpg">https://upload.wikimedia.org/wikipedia/commons/3/37/African_Bush_Elephant.jpg</a></figcaption></figure><p>The output will look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*JUgxIkYpZGuJBEsDmRZ3hg.png" /><figcaption>Top 3 predicted categories and their probabilities</figcaption></figure><h4>Prediction function</h4><p>To start, let’s load the keras.preprocessing and the keras.applications.resnet50 modules (resnet50 paper: <a href="https://arxiv.org/pdf/1512.03385">Deep Residual Learning for Image Recognition</a>), and load the ResNet50 model using weights that have been trained on the ImageNet ILSVRC competition:</p><pre>import numpy as np<br>from keras.preprocessing import image<br>from keras.applications.resnet50 import ResNet50, preprocess_input, decode_predictions</pre><pre>model = ResNet50(weights=&#39;imagenet&#39;)</pre><p>Then we can define a predict function:</p><pre>def predict(model, img, target_size, top_n=3):<br>  &quot;&quot;&quot;Run model prediction on image<br>  Args:<br>    model: keras model<br>    img: PIL format image<br>    target_size: (width, height) tuple<br>    top_n: # of top predictions to return<br>  Returns:<br>    list of predicted labels and their probabilities<br>  &quot;&quot;&quot;<br>  if img.size != target_size:<br>    img = img.resize(target_size)</pre><pre>  x = image.img_to_array(img)<br>  x = np.expand_dims(x, axis=0)<br>  x = preprocess_input(x)<br>  preds = model.predict(x)<br>  return decode_predictions(preds, top=top_n)[0]</pre><p>Note that to use the ResNet50 architecture, target_size must equal (224, 224). Many CNN architectures have a fixed input size and ResNet50 is one such architecture, where the inventors used a fixed size input of (224, 224).</p><p>image.img_to_array: converts a <a href="https://pillow.readthedocs.io/en/4.0.x/">PIL</a> format image to a <a href="http://www.numpy.org/">numpy</a> array</p><p>np.expand_dims: converts our (3, 224, 224) size image to (1, 3, 224, 2 24). The reason for this is that the model.predict function requires a 4 dimensional array as input, where the 4th dimension corresponds to the batch size. That means, if we wanted to, we could classify multiple images at once.</p><p>preprocess_input: zero-centers our image data using the mean channel values from the training dataset. This is an <em>extremely</em> important step that, if skipped, will cause all the predicted probabilities to be incorrect. This mean centering is what’s called <a href="https://en.wikipedia.org/wiki/Feature_scaling"><strong>data normalization</strong></a>, a fundamental concept in machine learning.</p><p>model.predict: runs inference on our data batch and returns predictions</p><p>decode_predictions: takes the coded labels associated with model.predict and returns human-readable labels from the ImageNet ILSVRC set.</p><p>The keras.applications module provides 4 off-the-shelf architectures: ResNet50, InceptionV3, VGG16, VGG19, XCeption. We arbitrarily chose ResNet50, but you are free to swap that out with any of the other off-the-shelf architectures. Checkout <a href="https://keras.io/applications/">https://keras.io/applications/</a> for additional information and references.</p><h4>Plotting</h4><p>We can use matplotlib to print the output in a horizontal bar graph like so:</p><pre>def plot_preds(image, preds):  <br>  &quot;&quot;&quot;Displays image and the top-n predicted probabilities <br>     in a bar graph  <br>  Args:    <br>    image: PIL image<br>    preds: list of predicted labels and their probabilities  <br>  &quot;&quot;&quot;  <br>  #image<br>  plt.imshow(image)<br>  plt.axis(&#39;off&#39;)<br>  <br>  #bar graph<br>  plt.figure()  <br>  order = list(reversed(range(len(preds))))  <br>  bar_preds = [pr[2] for pr in preds]<br>  labels = (pr[1] for pr in preds)<br>  plt.barh(order, bar_preds, alpha=0.5)<br>  plt.yticks(order, labels)<br>  plt.xlabel(&#39;Probability&#39;)<br>  plt.xlim(0, 1.01)<br>  plt.tight_layout()<br>  plt.show()</pre><h4>Main</h4><p>In order to have this command line usage:</p><pre>1. python classify.py --image African_Bush_Elephant.jpg<br>2. python classify.py --image_url <a href="http://i.imgur.com/wpxMwsR.jpg">http://i.imgur.com/wpxMwsR.jpg</a></pre><p>We’ll define a main function as follows:</p><pre>if __name__==&quot;__main__&quot;:<br>  a = argparse.ArgumentParser()<br>  a.add_argument(&quot;--image&quot;, help=&quot;path to image&quot;)<br>  a.add_argument(&quot;--image_url&quot;, help=&quot;url to image&quot;)<br>  args = a.parse_args()</pre><pre>if args.image is None and args.image_url is None:<br>    a.print_help()<br>    sys.exit(1)</pre><pre>if args.image is not None:<br>    img = Image.open(args.image)<br>    plot_preds(predict(model, img, target_size))</pre><pre>if args.image_url is not None:<br>    response = requests.get(args.image_url)<br>    img = Image.open(BytesIO(response.content))<br>    plot_preds(predict(model, img, target_size))</pre><p>The image_url option uses the python Requests library to easily download an image from any URL!</p><h3>We’re done!</h3><p>Once you put all the above code together, you have the beginnings of an image recognition system! See the complete program and example images here on <a href="https://github.com/DeepLearningSandbox/DeepLearningSandbox/tree/master/image_recognition">Github</a>.</p><p>The next post in our series will cover the situation where your object of interest is not one of the ImageNet ILSVRC categories:</p><ol><li><strong>Build an image recognition system for a 1000 everyday object categories (ImageNet ILSVRC) using Keras and TensorFlow (this post)</strong></li><li>Build an image recognition system for any customizable object categories using transfer learning and fine-tuning in Keras and TensorFlow</li><li>Build a real-time bounding-box object detection system for hundreds of everyday object categories (PASCAL VOC, COCO)</li><li>Build a web service for any image recognition or object detection system</li></ol><h4>Additional examples</h4><p>Let’s try a few more examples!</p><ol><li>python classify.py --image_url <a href="http://i.imgur.com/cg37Ojo.jpg">http://i.imgur.com/cg37Ojo.jpg</a></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*jDGjTqHDAkngjJGPjMkflg.png" /><figcaption>Image and top 3 predicted labels along with their probabilities</figcaption></figure><p>2. python classify.py --image_url <a href="http://i.imgur.com/4FIOwAN.jpg">http://i.imgur.com/4FIOwAN.jpg</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*rGqhRaeRTGQ9V3oBFQ-9eQ.png" /><figcaption>Image and top 3 predicted labels along with their probabilities</figcaption></figure><p>3. python classify.py --image_url <a href="http://goo.gl/t3Gh5P">http://goo.gl/t3Gh5P</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IAaJm_B5ADIcgoUS-wWlsA.png" /><figcaption>Image and top 3 predicted labels along with their probabilities</figcaption></figure><p>If you enjoyed the article, click the ❤ and sign up:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F19b29f%3Fas_embed%3Dtrue&amp;url=https%3A%2F%2Fupscri.be%2F19b29f%2F&amp;image=https%3A%2F%2Fupscri.be%2Fmedia%2Fform.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/81a498890bd2a9f3c854da5383b33700/href">https://medium.com/media/81a498890bd2a9f3c854da5383b33700/href</a></iframe><p>If you have any questions contact me at greg.ht.chu@gmail.comor message me on <a href="https://www.linkedin.com/in/greghchu/">LinkedIn</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=559856e04699" width="1" height="1" alt=""><hr><p><a href="https://medium.com/deeplearningsandbox/how-to-build-an-image-recognition-system-using-keras-and-tensorflow-for-a-1000-everyday-object-559856e04699">How to build an image recognition system using Keras and Tensorflow for a 1000 everyday object…</a> was originally published in <a href="https://medium.com/deeplearningsandbox">Deep Learning Sandbox</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>