<?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 Tejan Irla on Medium]]></title>
        <description><![CDATA[Stories by Tejan Irla on Medium]]></description>
        <link>https://medium.com/@tejanirla4?source=rss-3fa7549b5e0c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*63vbyyLkoKwblmUbfypbLA.jpeg</url>
            <title>Stories by Tejan Irla on Medium</title>
            <link>https://medium.com/@tejanirla4?source=rss-3fa7549b5e0c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 17:38:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tejanirla4/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[Predicting Taxi fares in NYC using Google Cloud AI Platform (Billion + rows) Part 3]]></title>
            <link>https://medium.com/data-science/predicting-taxi-fares-in-nyc-using-google-cloud-ai-platform-billion-rows-part-3-3c6a6b5cd1e2?source=rss-3fa7549b5e0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c6a6b5cd1e2</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[hyperparameter-tuning]]></category>
            <category><![CDATA[big-data-analytics]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Tejan Irla]]></dc:creator>
            <pubDate>Fri, 22 Nov 2019 01:28:44 GMT</pubDate>
            <atom:updated>2019-11-22T04:16:17.714Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kcEJ_C4qFOHgpEXUMU-TNA.jpeg" /><figcaption>Taxis | Photo by Nout Gons on <a href="https://www.pexels.com/photo/action-america-architecture-avenue-378570/">pexels.com</a></figcaption></figure><p>The objective of this series of articles is to create a Machine Learning model that is able to estimate taxi fares in NYC before the ride commences. A version of this model has applications in the rideshare industry where users like to know the cost of the ride as soon as selecting the destination.</p><p>In the previous two posts, we created a project on the Google Cloud Platform, cleaned the data, created features and ultimately trained a model on a small sample of this huge dataset locally. We were able to achieve an RMSE of 4.13.</p><ul><li><a href="https://towardsdatascience.com/predicting-taxi-fares-in-nyc-using-google-cloud-ai-platform-billion-rows-part-1-ac121832babf">Predicting Taxi fares in NYC using Google Cloud AI Platform(Billion + rows) Part 1</a></li><li><a href="https://towardsdatascience.com/predicting-taxi-fares-in-nyc-using-google-cloud-ai-platform-billion-rows-part-2-f0191a70dea8">Predicting Taxi fares in NYC using Google Cloud AI Platform (Billion + rows) Part 2</a></li></ul><p>In this post, we train on the entire dataset and perform hyperparameter tuning. Let’s begin.</p><p>I have already stored the entire dataset of 130 GB from Bigquery into my storage bucket on GCP as sharded CSV files. TensorFlow can directly read from BigQuery, but the process is very slow and it is always better to work with CSV files as we did in my previous <a href="https://towardsdatascience.com/predicting-taxi-fares-in-nyc-using-google-cloud-ai-platform-billion-rows-part-2-f0191a70dea8">post </a>with a sample.</p><h4>Cloud AI Platform</h4><p>There are two main steps to train on the cloud:</p><ul><li>Make the code a Python package (create <strong>__init__.py, task.py,</strong> and <strong>model.py </strong>files)</li><li>Submit the Python package using gcloud to Cloud AI Platform</li></ul><p><strong>Create task.py</strong></p><pre>%%writefile your_path/task.py<br>import argparse<br>import json<br>import os</pre><pre>from . import model</pre><pre>if __name__ == &quot;__main__&quot;:<br>    parser = argparse.ArgumentParser()<br>    parser.add_argument(<br>        &quot;--hidden_units&quot;,<br>        help = &quot;Hidden layer sizes,<br>        type = str,<br>        default = &quot;16,16&quot;<br>    )<br>    parser.add_argument(<br>        &quot;--train_data_path&quot;,<br>        help = &quot;Path to training data&quot;,<br>        required = True<br>    )<br>    parser.add_argument(<br>        &quot;--train_steps&quot;,<br>        help = &quot;Training steps&quot;,<br>        type = int,<br>        default = 1000<br>    )<br>    parser.add_argument(<br>        &quot;--eval_data_path&quot;,<br>        help = &quot;Path to evaluation data&quot;,<br>        required = True<br>    )<br>    parser.add_argument(<br>        &quot;--output_dir&quot;,<br>        help = &quot;Output Directory&quot;,<br>        required = True<br>    )<br>    parser.add_argument(<br>        &quot;--job-dir&quot;,<br>        help=&quot;Required by gcloud&quot;,<br>    )<br>    args = parser.parse_args().__dict__<br>    <br>    # Append trial_id r<br>    args[&quot;output_dir&quot;] = os.path.join(<br>        args[&quot;output_dir&quot;],<br>        json.loads(<br>            os.environ.get(&quot;TF_CONFIG&quot;, &quot;{}&quot;)<br>        ).get(&quot;task&quot;, {}).get(&quot;trial&quot;, &quot;&quot;)<br>    ) <br>    # Run<br>    model.train_and_evaluate(args)</pre><p><strong>Create model.py</strong></p><p>The Hyperparameters that are to be tuned are needed to be passed in as command-line arguments</p><pre>%%writefile your_path/model.py<br>import tensorflow as tf<br>import numpy as np<br>import shutil<br>print(tf.__version__)</pre><pre>CSV_COLUMN_NAMES = [&quot;fare_amount&quot;,&quot;dayofweek&quot;,&quot;hourofday&quot;,&quot;pickuplon&quot;,&quot;pickuplat&quot;,&quot;dropofflon&quot;,&quot;dropofflat&quot;]<br>CSV_DEFAULTS = [[0.0],[1],[0],[-74.0],[40.0],[-74.0],[40.7]]</pre><pre>def read_dataset(csv_path):<br>    def _parse_row(row):<br>        # Every row into a list of tensors<br>        fields = tf.decode_csv(records = row, record_defaults = CSV_DEFAULTS)</pre><pre># All the features into a dictionary<br>        features = dict(zip(CSV_COLUMN_NAMES, fields))<br>        <br>        # Feature Engineering<br>        features = add_engineered_features(features)<br>        <br>        # Pop the fare_amount <br>        label = features.pop(&quot;fare_amount&quot;)</pre><pre>return features, label<br>    <br>    # Create a dataset<br>    dataset = tf.data.Dataset.list_files(file_pattern = csv_path) # (i.e. data_file_*.csv)<br>    dataset = dataset.flat_map(map_func = lambda filename:tf.data.TextLineDataset(filenames = filename).skip(count = 1))<br>    dataset = dataset.map(map_func = _parse_row)<br>    <br>    return dataset</pre><pre>def train_input_fn(csv_path, batch_size = 128):<br>    # Create the training dataset<br>    dataset = read_dataset(csv_path)<br>      <br>    # Shuffle<br>    dataset = dataset.shuffle(buffer_size = 1000).repeat(count = None).batch(batch_size = batch_size)<br>   <br>    return dataset</pre><pre>def eval_input_fn(csv_path, batch_size = 128):<br>    # Create the Validation dataset<br>    dataset = read_dataset(csv_path)</pre><pre># Shuffle and batch <br>    dataset = dataset.batch(batch_size = batch_size)<br>   <br>    return dataset<br>  <br># One Hot Encoding<br>fc_dayofweek = tf.feature_column.categorical_column_with_identity(key = &quot;dayofweek&quot;, num_buckets = 7)<br>fc_hourofday = tf.feature_column.categorical_column_with_identity(key = &quot;hourofday&quot;, num_buckets = 24)</pre><pre># Bucketize latitudes and longitudes<br>NBUCKETS = 16<br>latbuckets = np.linspace(start = 38.0, stop = 42.0, num = NBUCKETS).tolist()<br>lonbuckets = np.linspace(start = -76.0, stop = -72.0, num = NBUCKETS).tolist()<br>fc_bucketized_plat = tf.feature_column.bucketized_column(source_column = tf.feature_column.numeric_column(key = &quot;pickuplon&quot;), boundaries = lonbuckets)<br>fc_bucketized_plon = tf.feature_column.bucketized_column(source_column = tf.feature_column.numeric_column(key = &quot;pickuplat&quot;), boundaries = latbuckets)<br>fc_bucketized_dlat = tf.feature_column.bucketized_column(source_column = tf.feature_column.numeric_column(key = &quot;dropofflon&quot;), boundaries = lonbuckets)<br>fc_bucketized_dlon = tf.feature_column.bucketized_column(source_column = tf.feature_column.numeric_column(key = &quot;dropofflat&quot;), boundaries = latbuckets)</pre><pre># Crossed Column<br>fc_crossed_day_hr = tf.feature_column.crossed_column(keys = [fc_dayofweek, fc_hourofday], hash_bucket_size = 24 * 7)</pre><pre>def add_engineered_features(features):<br>    <br>    <br>    features[&quot;latdiff&quot;] = features[&quot;pickuplat&quot;] - features[&quot;dropofflat&quot;] <br>    features[&quot;londiff&quot;] = features[&quot;pickuplon&quot;] - features[&quot;dropofflon&quot;] <br>    features[&quot;euclidean_dist&quot;] = tf.sqrt(x = features[&quot;latdiff&quot;]**2 + features[&quot;londiff&quot;]**2)<br>    features[&quot;dayofweek&quot;] = features[&quot;dayofweek&quot;] - 1</pre><pre>return features</pre><pre>#1. Created using tf.feature_column module<br>    tf.feature_column.indicator_column(categorical_column = fc_crossed_day_hr),<br>    fc_bucketized_plat,<br>    fc_bucketized_plon,<br>    fc_bucketized_dlat,<br>    fc_bucketized_dlon,<br>    #2. Created in the input functions<br>    tf.feature_column.numeric_column(key = &quot;latdiff&quot;),<br>    tf.feature_column.numeric_column(key = &quot;londiff&quot;),<br>    tf.feature_column.numeric_column(key = &quot;euclidean_dist&quot;) <br>]</pre><pre>def serving_input_receiver_fn():<br>    receiver_tensors = {<br>        &#39;dayofweek&#39; : tf.placeholder(dtype = tf.int32, shape = [None]), # shape is vector to allow batch of requests<br>        &#39;hourofday&#39; : tf.placeholder(dtype = tf.int32, shape = [None]),<br>        &#39;pickuplon&#39; : tf.placeholder(dtype = tf.float32, shape = [None]), <br>        &#39;pickuplat&#39; : tf.placeholder(dtype = tf.float32, shape = [None]),<br>        &#39;dropofflat&#39; : tf.placeholder(dtype = tf.float32, shape = [None]),<br>        &#39;dropofflon&#39; : tf.placeholder(dtype = tf.float32, shape = [None]),<br>    }<br>    <br>    features = add_engineered_features(receiver_tensors) # &#39;features&#39; is what is passed on to the model<br>    <br>    return tf.estimator.export.ServingInputReceiver(features = features, receiver_tensors = receiver_tensors)<br>  <br>def train_and_evaluate(params):<br>    OUTDIR = params[&quot;output_dir&quot;]</pre><pre>model = tf.estimator.DNNRegressor(<br>        hidden_units = params[&quot;hidden_units&quot;].split(&quot;,&quot;), <br>        feature_columns = feature_cols, <br>        model_dir = OUTDIR,<br>        config = tf.estimator.RunConfig(<br>            tf_random_seed = 1, # for reproducibility<br>            save_checkpoints_steps = max(100, params[&quot;train_steps&quot;] // 10)<br>        ) <br>    )</pre><pre>def my_rmse(labels, predictions):<br>        pred_values = tf.squeeze(input = predictions[&quot;predictions&quot;], axis = -1)<br>        return {&quot;rmse&quot;: tf.metrics.root_mean_squared_error(labels = labels, predictions = pred_values)}<br>    <br>    model = tf.contrib.estimator.add_metrics(model, my_rmse)</pre><pre>train_spec = tf.estimator.TrainSpec(<br>        input_fn = lambda: train_input_fn(params[&quot;train_data_path&quot;]),<br>        max_steps = params[&quot;train_steps&quot;])</pre><pre>exporter = tf.estimator.FinalExporter(name = &quot;exporter&quot;, serving_input_receiver_fn = serving_input_receiver_fn)</pre><pre>eval_spec = tf.estimator.EvalSpec(<br>        input_fn = lambda: eval_input_fn(params[&quot;eval_data_path&quot;]),<br>        steps = None,<br>        start_delay_secs = 1, <br>        throttle_secs = 1, <br>        exporters = exporter)</pre><pre>tf.logging.set_verbosity(v = tf.logging.INFO) # so loss is printed during training<br>    shutil.rmtree(path = OUTDIR, ignore_errors = True) # start fresh each time</pre><pre>tf.estimator.train_and_evaluate(model, train_spec, eval_spec)</pre><p><strong>Create Hyperparameter Tuning configuration</strong></p><p>Cloud AI Platform uses <strong>Bayesian Optimization</strong> by default. We can also use <strong>Grid Search</strong> or Random Search when tuning only a few parameters.</p><p>Here we are tuning only one parameter that is the number of hidden units. All trials are run in parallel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*vSSnNURx_57P4UsgGz7b-A.png" /></figure><p><strong>Enable the AI Platform API</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*6FBeRfE5jKqY4N_V886G5A.png" /></figure><p><strong>Run the training Job</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*BNjnCRMW6eSHE-5NIDIOVg.png" /></figure><p>We can run this on a part of the dataset to get a better idea and then try the best combination on the entire data.</p><p>I found the best configuration of hidden units to be ’<strong>64, 64, 64, 8</strong>’ with an RMSE of <strong>3.98.</strong></p><p>This concludes our three-part series. A lot of improvement can be made by following different approaches such as engineering new features, selecting a different model, tuning more hyperparameters, etc. Creating the best possible model requires patience and a lot of trial and error.</p><p>Resources: <a href="https://www.coursera.org/specializations/machine-learning-tensorflow-gcp">Machine Learning with TensorFlow on Google Cloud Platform</a></p><p>Connect with me on <a href="http://www.linkedin.com/in/tejan-irla">LinkedIn</a>. You can find the full code <a href="https://github.com/tejanirla/taxi_fare_prediction/blob/master/taxi_fare_model_creation.ipynb">here</a>.</p><p>Cheers !!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c6a6b5cd1e2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/predicting-taxi-fares-in-nyc-using-google-cloud-ai-platform-billion-rows-part-3-3c6a6b5cd1e2">Predicting Taxi fares in NYC using Google Cloud AI Platform (Billion + rows) Part 3</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[Predicting Taxi fares in NYC using Google Cloud AI Platform (Billion + rows) Part 2]]></title>
            <link>https://medium.com/data-science/predicting-taxi-fares-in-nyc-using-google-cloud-ai-platform-billion-rows-part-2-f0191a70dea8?source=rss-3fa7549b5e0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0191a70dea8</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[tensorflow]]></category>
            <dc:creator><![CDATA[Tejan Irla]]></dc:creator>
            <pubDate>Thu, 24 Oct 2019 22:44:37 GMT</pubDate>
            <atom:updated>2019-11-01T03:08:39.562Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uFxKE52I3Y4Ym12GCJGSnw.jpeg" /><figcaption>Taxis | Photo by Life of Pix on <a href="https://www.pexels.com/photo/new-york-street-cabs-taxis-8247/">pexels.com</a></figcaption></figure><p>In this series of articles, we are working on a real-world dataset of taxi rides in NYC which is hosted in BigQuery to be able to estimate the fare amount.</p><p>In the <a href="https://towardsdatascience.com/predicting-taxi-fares-in-nyc-using-google-cloud-ai-platform-billion-rows-part-1-ac121832babf">previous post</a>, we set up a project on the Google Cloud Platform, started an AI notebook instance with TensorFlow pre-installed, and prepared/cleaned/sampled the data. Now comes the part where we build a model to predict the target variable.</p><p>We are going to use <strong>tf.estimator</strong>, a high-level TensorFlow API to build our models. Detailed information can be found <a href="http://www.tensorflow.org/">here</a>.</p><p>There are four major steps to use this API.</p><ul><li>Create a function to import the dataset</li><li>Define the feature columns</li><li>Instantiate the Estimator</li><li>Train/Evaluate</li></ul><h4><strong>Create a function to import the dataset</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XzlUSDuvvO6x_mo_S3ho2Q.png" /></figure><p>An alternative would be to use the tf.data.experimental.make_csv_dataset function to read the dataset.</p><p>In case of smaller datasets, we can load them in pandas dataframes as they would fit into memory. We can read these dataframes using tf.data.Dataset.from_tensor_slices</p><p><strong>Functions to import the training and validation sets</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*frA42UWIdJGXwg_egOVfvg.png" /></figure><h4>Define the Feature Columns</h4><p>One of the most important steps in any predictive analytics project is feature engineering. With some experience, domain expertise, and good old fashioned trial and error, you can engineer features that significantly improve the end result.</p><p><strong>Bucketize latitudes and longitudes</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oxwsE-2xEMDVIpsx68lsRg.png" /></figure><p><strong>One Hot Encoding</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mtxrS_4b1MKunh0UASJKKQ.png" /></figure><p><strong>tf.feature_column.crossed_column</strong></p><p>Create a feature using tf.feature_column.crossed_column that gives us information about the combination of time and day of week. For example, fares can be significantly different for a Friday night w.r.t. Sunday night.</p><pre>fc_crossed_day_hr = tf.feature_column.crossed_column(keys = [fc_dayofweek, fc_hourofday], hash_bucket_size = 24 * 7)</pre><p>Create a function so that we can create new features at the same time we read data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QBfhMWnSJAxiiORttCYXoQ.png" /></figure><p>We create Euclidean Distance between the coordinates as a feature along with separate latitude-difference and longitude-difference which would give us information about ride direction.</p><p>Finally, create a list of the feature columns we decide to train our model on and create the Serving Input Receiver function</p><h4>Train/Evaluate</h4><p>Linear Model</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TVeGZ2wI4_QBXBC1c7ojBA.png" /></figure><blockquote>RMSE is <strong>7.4</strong></blockquote><p>Now, let’s train our model using a DNN regressor which would better understand the non linear relationships.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*stFcfR15LT3xfKgAMrg9Ig.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ACzq5AZCUVmCKyjyPCFMsQ.png" /></figure><blockquote>We get an rmse of <strong>4.13</strong></blockquote><p>In the next post, we will tune the <strong>hyperparameters </strong>to improve on this result, and train on the entire data comprising of 1 Billion plus rides. As you can guess, we cannot do this on our laptop. Time to move to the cloud.</p><p>Resources: <a href="https://www.coursera.org/specializations/machine-learning-tensorflow-gcp">Machine Learning with TensorFlow on Google Cloud Platform</a></p><p>Connect with me on <a href="http://www.linkedin.com/in/tejan-irla">LinkedIn</a>. You can find the full code <a href="https://github.com/tejanirla/taxi_fare_prediction/blob/master/taxi_fare_model_creation.ipynb">here</a>.</p><p>Cheers !!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0191a70dea8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/predicting-taxi-fares-in-nyc-using-google-cloud-ai-platform-billion-rows-part-2-f0191a70dea8">Predicting Taxi fares in NYC using Google Cloud AI Platform (Billion + rows) Part 2</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[Predicting Taxi fares in NYC using Google Cloud AI Platform(Billion + rows) Part 1]]></title>
            <link>https://medium.com/data-science/predicting-taxi-fares-in-nyc-using-google-cloud-ai-platform-billion-rows-part-1-ac121832babf?source=rss-3fa7549b5e0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac121832babf</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[predictive-analytics]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Tejan Irla]]></dc:creator>
            <pubDate>Mon, 07 Oct 2019 03:31:55 GMT</pubDate>
            <atom:updated>2019-10-31T22:41:13.007Z</atom:updated>
            <content:encoded><![CDATA[<h3>Predicting Taxi fares in NYC using Google Cloud AI Platform (Billion + rows) Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C291SIqt9-QFSP6-WSfpvA.jpeg" /><figcaption>Taxis | Photo by Francesco Ungaro on pexels.com</figcaption></figure><p>This project aims at creating a Machine Learning model to estimate taxi fares in New York City using a dataset corresponding to taxi rides which is hosted in BigQuery. There are more than a <strong>Billion </strong>rows with a size of 130 GB. You can find it <a href="https://console.cloud.google.com/bigquery?project=bigquery-public-data&amp;p=nyc-tlc&amp;d=yellow&amp;t=trips&amp;page=table">here</a>. This post is based on my experience with the Machine Learning with TensorFlow on Google Cloud Platform <a href="https://www.coursera.org/specializations/machine-learning-tensorflow-gcp">Specialization</a>.</p><p>To begin, we’ll have to set up a project on the Google Cloud Platform and start a notebook instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*qs4A57XyxWB3vi56lLhWRw.png" /></figure><p>This instance would cost us around <strong>$0.14</strong> per hour. We also need to enable the Compute Engine API and create a storage bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*Dm_Dvmpic7fZrGfuAiajCQ.png" /></figure><h4><strong>Data Preparation</strong></h4><p><strong>Install the BigQuery library and preview the data</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*r10pyfatWemFeTmOD90kGA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DrihbG_ivcuorbIgdPVt7g.png" /></figure><p>We used the <strong>RAND() </strong>function to take a <strong>small sample</strong> from this humungous dataset.</p><p>The disadvantage is that we get a different sample every time we run this query. Thus, we’ll use a hash function.</p><pre>MOD(ABS(FARM_FINGERPRINT(CAST(pickup_datetime AS STRING))), 5000)= 1</pre><p>This function enables us to get a constant sample with <strong>0.02%</strong> of the original data. It would take enormous computing power to utilize the entire dataset for exploration. I plan on building a model using the entire dataset in the future.</p><p><strong>Load the data into a Pandas Dataframe</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*QYF8-Q2SybD9no3fsDFN4Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iuSrbrfWLQzyrIRORbYqmA.png" /></figure><p>We definitely need to clean our data. For example, the latitude and longitude values are off (latitude should be between -90 and 90; longitude should be between -180 and 180). Some trips have a negative fare amount and some have a zero passenger count.</p><p>Let’s plot <strong>trip_distance</strong> vs <strong>fare_amount</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*9SS0bKhw3QxsR8QEoVqivA.png" /></figure><p>Some bad data is coded as zero. Also, we are not going to include tips in our prediction as they tend to be unpredictable. Our target variable would be <strong>fare_amount + tolls_amount</strong></p><p><strong>Our predictors would be:</strong></p><blockquote>pickup_datetime</blockquote><blockquote>pickup_longitude</blockquote><blockquote>pickup_latitude</blockquote><blockquote>dropoff_longitude</blockquote><blockquote>dropoff_latitude</blockquote><p>We have selected these as they are best in line with our objective. One can argue that <strong>trip_distance </strong>can help us determine the fare, but we are excluding it as it cannot always be known in advance. Our project might have applications in the ride-hailing industry where we can predict the trip cost in advance, and the location coordinates of the source/destination should be chosen over trip_distance for accuracy.</p><p><strong>Data Cleaning</strong></p><p>We follow the following to filter unreasonable data:</p><ul><li>Fare amounts should be greater than <strong>$2.5</strong></li><li>Source/Destination location coordinates should be within NYC limits</li><li>Passenger Counts cannot be zero</li><li>Trip Distance cannot be zero</li></ul><pre>SELECT<br>  (tolls_amount + fare_amount) AS fare_amount, -- label<br>  pickup_datetime,<br>  pickup_longitude, <br>  pickup_latitude, <br>  dropoff_longitude, <br>  dropoff_latitude<br>FROM<br>  `nyc-tlc.yellow.trips`<br>WHERE<br>  -- Clean Data<br>  trip_distance &gt; 0<br>  AND passenger_count &gt; 0<br>  AND fare_amount &gt;= 2.5<br>  AND pickup_longitude &gt; -78<br>  AND pickup_longitude &lt; -70<br>  AND dropoff_longitude &gt; -78<br>  AND dropoff_longitude &lt; -70<br>  AND pickup_latitude &gt; 37<br>  AND pickup_latitude &lt; 45<br>  AND dropoff_latitude &gt; 37<br>  AND dropoff_latitude &lt; 45<br>  -- repeatable 1/5000th sample<br>  AND MOD(ABS(FARM_FINGERPRINT(CAST(pickup_datetime AS STRING))),5000) = 1</pre><p>Let us also create some categorical features by getting <strong>dayofweek </strong>and <strong>hourofday </strong>from <strong>pickup _datetime</strong></p><pre>SELECT<br>  (tolls_amount + fare_amount) AS fare_amount, -- label<br>  EXTRACT(DAYOFWEEK from pickup_datetime) AS dayofweek,<br>  EXTRACT(HOUR from pickup_datetime) AS hourofday,<br>  ------------------<br>  ------------------</pre><p><strong>Split the data into Train, Validation, and Test sets</strong></p><p>We split our <strong>1/5000th</strong> sample <strong>70–15–15</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*0HYhT1k1tNawh3sikF9Few.png" /></figure><p><strong>Write the data to CSV</strong></p><p>In the next steps, we are going to create a machine learning model using <strong>TensorFlow </strong>which is slow to read files directly from BigQuery. Thus, we write our data out as <strong>.csv</strong> files</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*5G0uFXMLXSpRK9tgmMZR4w.png" /></figure><p>Given that we are only using a sample (0.02%) of the total data, we still have <strong>151k </strong>rows to train on which is pretty good.</p><p>The next post where we discuss model creation can be found <a href="https://medium.com/@tejanirla4/predicting-taxi-fares-in-nyc-using-google-cloud-ai-platform-billion-rows-part-2-f0191a70dea8">here</a>.</p><p>Connect with me on <a href="http://www.linkedin.com/in/tejan-irla">LinkedIn</a>. You can find the full code <a href="https://github.com/tejanirla/cab_fare_prediction/blob/master/taxi_fare_data_preparation.ipynb">here</a>.</p><p>Cheers !!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac121832babf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/predicting-taxi-fares-in-nyc-using-google-cloud-ai-platform-billion-rows-part-1-ac121832babf">Predicting Taxi fares in NYC using Google Cloud AI Platform(Billion + rows) Part 1</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[Transfer Learning using Inception-v3 for Image Classification]]></title>
            <link>https://medium.com/analytics-vidhya/transfer-learning-using-inception-v3-for-image-classification-86700411251b?source=rss-3fa7549b5e0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/86700411251b</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[transfer-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Tejan Irla]]></dc:creator>
            <pubDate>Sat, 05 Oct 2019 20:01:55 GMT</pubDate>
            <atom:updated>2019-10-08T13:35:21.500Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wdMSQUIwn_ZGeFDpaguyXQ.jpeg" /><figcaption>Photo by Pixabay on <a href="https://www.pexels.com/photo/girls-on-desk-looking-at-notebook-159823/">pexels.com</a></figcaption></figure><p>In my <a href="http://medium.com/analytics-vidhya/end-to-end-image-classification-project-using-tensorflow-46e78298fa2f"><strong>previous post</strong></a>, I worked on a subset of the original Dogs vs. Cats <a href="http://www.kaggle.com/c/dogs-vs-cats/data">Dataset </a>(3000 images sampled from the original dataset of 25000 images) to build an image classifier capable of classifying images of Dogs and Cats with <strong>82%</strong> accuracy.</p><p>This project is in continuation with the previous one where we try to improve our performance and is based on the TensorFlow in Practice <a href="https://www.coursera.org/specializations/tensorflow-in-practice?">Specialization</a>.</p><p>When we have a relatively small dataset, a super-effective technique is to use <strong>Transfer Learning</strong> where we use a pre-trained model. This model has been trained on an extremely large dataset, and we would be able to transfer weights which were learned through hundreds of hours of training on multiple high powered GPUs.</p><p>Many such models are open-sourced such as VGG-19 and Inception-v3. They were trained on millions of images with extremely high computing power which can be very expensive to achieve from scratch.</p><p>We are using the <strong>Inception-v3</strong> model in the project.</p><p>Transfer Learning has become immensely popular because it considerably reduces training time, and requires a lot less data to train on to increase performance.</p><p>Let&#39;s begin.</p><p><strong>Get the data</strong> (3000 total images)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*lltT_OgCu2k1YW7s8Swtow.png" /></figure><p><strong>Import the Inception-v3 model</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*xrcn9CUdGvC5eaEoZBGYTA.png" /></figure><p>We are going to use all the layers in the model except for the last fully connected layer as it is specific to the <a href="https://http//image-net.org/challenges/LSVRC/">ImageNet</a> competition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m7rtEnpG1kKCygoi027XUw.png" /></figure><p>Make all the layers non-trainable (We can retrain some of the lower layers to increase performance. Keep in mind that this may lead to overfitting)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*r7ZnbFeXu2sfD4Bq4G3nmA.png" /></figure><p>We use binary_crossentropy as the loss metric as we have 2 target classes (it&#39;s a binary classification problem)</p><p>Our optimizer is <strong>RMSprop</strong> with a learning rate of <strong>0.0001</strong> (We can experiment with this; Adam and Adagrad optimizers would also work well)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*aM4S3-3kce_mIvXvRk5KBg.png" /></figure><p>After rescaling the images, and using Image Augmentation, we flow them in batches of 20 using train_datagen and test_datagen. Details can be found in my <a href="https://medium.com/analytics-vidhya/end-to-end-image-classification-project-using-tensorflow-46e78298fa2f">previous post</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*tDQI9rJV3oIxJExGDDB7FA.png" /></figure><p>We have <strong>2000 </strong>training images and a <strong>1000 </strong>for validation.</p><p><strong>Let’s Train</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*G-C9rmvpXUTOW9LeLhjReQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*cE3028uZfAcQ0hHS__vUAw.png" /></figure><p>After about 35 minutes, we were able to achieve an accuracy of <strong>94%. </strong>A callback can very easily be implemented after we reach a certain accuracy.</p><p>This is the kind of result we were hoping for using <strong>Transfer Learning</strong>; Building upon a pre-trained model and using it in our custom application which was able to achieve great performance after training on just 2000 images.</p><p>Another approach to this problem would be not using all the layers of Inception-v3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*TmTWz7bEXTk1r8n2qiL_jA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*IQHPLIT4bavCDc5U0xVh5g.png" /></figure><p>Here we were able to achieve an accuracy of <strong>96%</strong> using a callback.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*z4PtWSDpFL0QNbz0kLK7uw.png" /></figure><p>As you can see, <strong>Transfer Learning</strong> has great applications in Computer Vision.</p><p>Not everyone can afford weeks of training in addition to access to millions of images to build a high performing CNN model for their custom use case, and this is where Transfer Learning comes in. You get the power and the flexibility to retrain some of the lower layers (as per your target classes) using a reasonable amount of resources. <a href="https://medium.com/datadriveninvestor/image-classifier-using-create-ml-core-ml-and-vision-framework-in-swift-345557960786">Here’s </a>an article aiming towards deploying such models through IOS apps.</p><p>Connect with me on <a href="http://www.linkedin.com/in/tejan-irla">LinkedIn</a>. You can find the full code <a href="https://github.com/tejanirla/image_classification/blob/master/transfer_learning.ipynb">here</a>.</p><p>Cheers !!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86700411251b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/transfer-learning-using-inception-v3-for-image-classification-86700411251b">Transfer Learning using Inception-v3 for Image Classification</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[End to End Image Classification project using TensorFlow]]></title>
            <link>https://medium.com/analytics-vidhya/end-to-end-image-classification-project-using-tensorflow-46e78298fa2f?source=rss-3fa7549b5e0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/46e78298fa2f</guid>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[image-classification]]></category>
            <dc:creator><![CDATA[Tejan Irla]]></dc:creator>
            <pubDate>Fri, 20 Sep 2019 21:38:06 GMT</pubDate>
            <atom:updated>2019-10-30T21:32:37.376Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Dogs vs Cats" src="https://cdn-images-1.medium.com/max/1024/1*akpXxcmwjsXlHz4gMvFEZQ.jpeg" /><figcaption>Photo by Snapwire on pexels.com</figcaption></figure><h4>The objective of this project is to develop a machine learning model capable of correctly classifying images of Dogs and Cats.</h4><p>We are going to work on a subset of the original Dogs vs. Cats Dataset (<strong>3000 images sampled from the original dataset of 25000 images</strong>) to demonstrate techniques such as <strong>Image Augmentation</strong> and <strong>Droputs,</strong> and how these techniques contribute in improving performance. The smaller dataset spares us a lot of computing power (and training time !). I plan on demonstrating my work on the original dataset which demands GPU/High Computing power soon. This post is based on my experience with the TensorFlow in Practice <a href="https://www.coursera.org/specializations/tensorflow-in-practice?">Specialization</a>.</p><p>I have also worked on building a model using <strong>Transfer Learning</strong> (Think hundreds of hrs of training on a Million + images used for our custom application) which builds on this project. You can find it <a href="https://medium.com/@tejanirla4/transfer-learning-using-inception-v3-for-image-classification-86700411251b?sk=212693ca04523fd3f9b100ac779d5a63"><strong>here</strong></a>.</p><p>The Original Dataset with 25,000 training images of dogs and cats can be found <a href="https://www.kaggle.com/c/dogs-vs-cats/data">here</a></p><h4>Get the data (Smaller Dataset)</h4><pre>!wget --no-check-certificate \<br>    <a href="https://storage.googleapis.com/mledu-datasets/cats_and_dogs_filtered.zip">https://storage.googleapis.com/mledu-datasets/cats_and_dogs_filtered.zip</a> \<br>    -O /tmp/cats_and_dogs_filtered.zip</pre><h4>Import libraries</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*iy_mOyrfEcLm-lfI6JrY4A.png" /></figure><p>The <strong>os</strong> library gives us access to the file system, and the <strong>zipfile</strong> library allows us to unzip the data.</p><h4>Create the respective directories</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*CLT4PgMyix8lWfHHB1mxhw.png" /></figure><p>The contents of the .zip are extracted to the base directory <strong>/tmp/cats_and_dogs_filtered.zip</strong></p><h4>Examples</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sr89IlNNZy7ASb7D1BjrCg.png" /></figure><h4>Model with 4 convolutional layers with 32, 64, 128 and 128 convolutions respectively</h4><p>Convolutions narrow down the content of the image to focus on specific details. It takes longer to run the model, but has a huge impact on accuracy.</p><p>We add convolutional layers, and flatten the final result to feed into the densely connected layers. As this is a 2 class classification problem, we use the <a href="https://en.wikipedia.org/wiki/Sigmoid_function">Sigmoid</a> function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gGl0oQaoakgBerY98KtVEA.png" /></figure><h4>Model Summary</h4><pre>Model: &quot;sequential&quot; _________________________________________________________________ Layer (type)                 Output Shape              Param #    ================================================================= conv2d (Conv2D)              (None, 148, 148, 32)      896        _________________________________________________________________ max_pooling2d (MaxPooling2D) (None, 74, 74, 32)        0          _________________________________________________________________ conv2d_1 (Conv2D)            (None, 72, 72, 64)        18496      _________________________________________________________________ max_pooling2d_1 (MaxPooling2 (None, 36, 36, 64)        0          _________________________________________________________________ conv2d_2 (Conv2D)            (None, 34, 34, 128)       73856      _________________________________________________________________ max_pooling2d_2 (MaxPooling2 (None, 17, 17, 128)       0          _________________________________________________________________ conv2d_3 (Conv2D)            (None, 15, 15, 128)       147584     _________________________________________________________________ max_pooling2d_3 (MaxPooling2 (None, 7, 7, 128)         0          _________________________________________________________________ flatten (Flatten)            (None, 6272)              0          _________________________________________________________________ dense (Dense)                (None, 512)               3211776    _________________________________________________________________ dense_1 (Dense)              (None, 1)                 513        ================================================================= Total params: 3,453,121 Trainable params: 3,453,121 Non-trainable params: 0 _________________________________________________________________</pre><p>The “<strong>output shape</strong>” column shows how the size of your feature map evolves in each successive layer. The convolution layers reduce the size of the feature maps by a bit due to padding, and each pooling layer halves the dimensions.</p><p>We use <strong>binary_crossentropy</strong> as the loss metric as we have <strong>2 target classes</strong> (its a <strong>binary classification problem</strong>)</p><p>Our optimizer is <strong>RMSprop</strong> with a learning rate of <strong>0.0001</strong> (We can experiment with this; <strong>Adam</strong> and <strong>Adagrad</strong> optimizers would also work well)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AR57HbfCmc50xJ35eG3JrQ.png" /></figure><h4>Rescale the Images</h4><p>The data generators read pictures in our source folders, convert them to <strong>float32 tensors</strong>, and feed them (with their labels) to our network. We’ll have one generator for the training images and one for the validation images.</p><p>Input data to the neural networks should be <strong>normalized</strong> to aid in processing. We will preprocess our images by normalizing the pixel values to be in the <strong>[0, 1] range (originally all values are in the [0, 255] range).</strong></p><p>In Keras this can be done via the <strong>keras.preprocessing.image.ImageDataGenerator</strong> class using the <strong>rescale</strong> parameter.</p><p>This <strong>ImageDataGenerator</strong> class allows you to instantiate generators of augmented image batches (and their labels) via <strong>.flow</strong>(data, labels) or <strong>.flow_from_directory</strong>(directory). These generators can then be used with the Keras model methods that accept data generators as inputs: <strong>fit_generator, evaluate_generator</strong>, and <strong>predict_generator</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VQLHz_mtS25-MMpbUVWkxA.png" /></figure><h4>Flow images in batches of 20 using train _datagen and test_datagen</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8rTl8fY_LRNCt9OVH6Kc_A.png" /></figure><h4>Training</h4><p>Will train for 100 epochs and then plot loss and accuracy</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mt0WgrPj3fR2nIxqh4w7OA.png" /></figure><h4>Accuracy and Loss</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xp-Lm2ubTqONSmFF6S2iqA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LHSTJqR3Y8AB7b-6cpZ-9A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sbw2zvOP4uAGiOZ_BBZfeg.png" /></figure><p>The graph show that we have a training accuracy of almost <strong>100%</strong>, while the validation accuracy is much lower in the <strong>70%-75%</strong> range. It’s a classic case of <strong>Overfitting.</strong></p><p>Our model does exceptionally well in case of images it has already seen and not so much with unseen images.</p><p>We can apply a simple yet very effective technique here called <strong>Image Augmentation</strong> where we change the images a bit by rotating them, squashing them, etc.</p><p>We can implement this using the <strong>ImageDataGenerator</strong> Class</p><pre>train_datagen = <strong>ImageDataGenerator</strong>(<br>      rescale=1./255,<br>      rotation_range=40,<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>      fill_mode=&#39;nearest&#39;)</pre><p>Some options that are available:</p><ul><li><strong>rotation_range</strong> is a value in degrees (0–180), a range within which to randomly rotate pictures.</li><li><strong>width_shift</strong> and <strong>height_shift</strong> are ranges (as a fraction of total width or height) within which to randomly translate pictures vertically or horizontally</li><li><strong>shear_range</strong> is for randomly applying shearing transformations</li><li><strong>zoom_range</strong> is for randomly zooming inside pictures</li><li><strong>horizontal_flip</strong> is for randomly flipping half of the images horizontally. This is relevant when there are no assumptions of horizontal assymmetry (e.g. real-world pictures)</li><li><strong>fill_mode</strong> is the strategy used for filling in newly created pixels, which can appear after a rotation or a width/height shift</li></ul><h4>Accuracy and Loss after implementing Image Augmentation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uqsgk7F-lrsJnaQuxg47yA.png" /></figure><p>As we can see, the accuracy and loss metrics have improved (although the training time increased), but we can do better. Let us try implementing <strong>Dropout</strong> which would help us with overfitting.</p><pre>model = tf.keras.models.Sequential([<br>    tf.keras.layers.Conv2D(32, (3,3), activation=&#39;relu&#39;, input_shape=(150, 150, 3)),<br>    tf.keras.layers.MaxPooling2D(2, 2),<br>    tf.keras.layers.Conv2D(64, (3,3), activation=&#39;relu&#39;),<br>    tf.keras.layers.MaxPooling2D(2,2),<br>    tf.keras.layers.Conv2D(128, (3,3), activation=&#39;relu&#39;),<br>    tf.keras.layers.MaxPooling2D(2,2),<br>    tf.keras.layers.Conv2D(128, (3,3), activation=&#39;relu&#39;),<br>    tf.keras.layers.MaxPooling2D(2,2),<br>    <strong>tf.keras.layers.Dropout(0.5), #Implementing Dropout</strong><br>    tf.keras.layers.Flatten(),<br>    tf.keras.layers.Dense(512, activation=&#39;relu&#39;),<br>    tf.keras.layers.Dense(1, activation=&#39;sigmoid&#39;)<br>])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kU7NoYKSxQ3djinG_aBn2g.png" /></figure><p>After implementing <strong>Dropout, </strong>both the training accuracy and validation accuracy are both about <strong>82%</strong> with a better loss curve.</p><p>This is a decent result considering that we trained on only <strong>2000</strong> training images versus the original dataset of <strong>22,500</strong> training images. In the case of Deep Learning, performance almost always increases when we train on more data. We can do significantly better by implementing Transfer Learning, where we use a pre-trained model as demonstrated in<a href="https://medium.com/@tejanirla4/transfer-learning-using-inception-v3-for-image-classification-86700411251b?sk=212693ca04523fd3f9b100ac779d5a63"><strong> this post</strong></a> which is in continuation of this project.</p><p>I expect that I will experience a better result when working with the full dataset next.</p><p><strong>We can also test our model with our own images with this piece of code which lets us choose one or more images from the file system. Then the images run through our model and give out results.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EVeG9JArpo3eZhiSDjc_yQ.png" /></figure><p>Connect with me on <a href="http://www.linkedin.com/in/tejan-irla">LinkedIn</a>. You can find the full code <a href="https://github.com/tejanirla/image_classification/blob/master/dogsVcats_subset.ipynb">here</a>.</p><p>Cheers !!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46e78298fa2f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/end-to-end-image-classification-project-using-tensorflow-46e78298fa2f">End to End Image Classification project using TensorFlow</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>