<?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 Shashwat Aggarwal on Medium]]></title>
        <description><![CDATA[Stories by Shashwat Aggarwal on Medium]]></description>
        <link>https://medium.com/@ishashwataggarwal?source=rss-9906779333ba------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*u7y4hAgbCdvaE9isL5rkhw.jpeg</url>
            <title>Stories by Shashwat Aggarwal on Medium</title>
            <link>https://medium.com/@ishashwataggarwal?source=rss-9906779333ba------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 20:19:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ishashwataggarwal/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[3D-MNIST Image Classification]]></title>
            <link>https://medium.com/@ishashwataggarwal/3d-mnist-b922a3d07334?source=rss-9906779333ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/b922a3d07334</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[image]]></category>
            <category><![CDATA[computer-vision]]></category>
            <dc:creator><![CDATA[Shashwat Aggarwal]]></dc:creator>
            <pubDate>Fri, 12 Jan 2018 17:28:40 GMT</pubDate>
            <atom:updated>2018-01-12T17:28:40.078Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fdWjdXMEeqZeiT2brfP4Zg.png" /><figcaption>2D vs 3D MNIST.</figcaption></figure><h4>Introduction</h4><p>The <a href="http://yann.lecun.com/exdb/mnist/">MNIST</a> <strong>[1]</strong> is the de facto <em>“hello world”</em> dataset for anyone getting started with computer vision. It contains a total of 70,000 examples divided into training and testing sets (6:1). Since its release in 1999, this classic dataset of handwritten images has served as the basis for benchmarking classification algorithms. Various emerging machine learning <a href="http://yann.lecun.com/exdb/mnist/">techniques</a> have been tested with the MNIST, that has remained a reliable resource for researchers and learners alike. More recently, Convolutional Neural Networks (CNN), a class of Deep Neural Networks have demonstrated immense success in the field of computer vision <strong>[2]</strong>. The MNIST dataset, in particular, has been effectively classified using architectures of this type, with the current state-of-the-art at a high <strong>99.79%</strong> accuracy <strong>[3]</strong>.</p><blockquote>If we can get almost perfect accuracy on MNIST, then why study its 3D version?</blockquote><p>MNIST is a good database for people who want to get acquainted with computer vision and pattern recognition methods to solve real-world problems, but most of the real-world vision problems like autonomous robots and scene understanding deal with 3D datasets. The availability of 3D data has been increasing rapidly as the use of sensors which provide 3D spatial readings in autonomous vehicles and robots becomes more prevalent. For this reason, the ability of these machines to automatically identify and make inferences about this data has become a crucial task for them to operate autonomously.</p><p>Recently, a 3D version of the MNIST was released on Kaggle <strong>[4]</strong><em>. </em>The dataset was created by generating 3D point clouds from the images of the digits in the original 2D MNIST. The script for generating point clouds can be found <a href="https://github.com/Harry-Zhi/3DMNIST/blob/master/3DMNIST.ipynb">here</a>. This dataset can be considered as a good starting point for getting familiar with 3D vision tasks. In this blog post, we explore this dataset and empirically compare the performance of various machine learning and deep learning based algorithms for the classification of 3D digits.</p><blockquote>And most importantly, get familiar with the somewhat less popular 3D-CNN! <em>:)</em></blockquote><h4>Overview of 3D MNIST Dataset</h4><p>The 3D MNIST dataset is available in <a href="https://support.hdfgroup.org/HDF5/whatishdf5.html">HDF5 file format</a>, <a href="https://www.kaggle.com/daavoo/3d-mnist/data">here</a>. The dataset contains 3D point clouds, i.e., sets of (x, y, z) coordinates generated from a portion of the original 2D MNIST dataset (around 5,000 images). The point clouds have zero mean and a maximum dimension range of 1. Each <a href="https://support.hdfgroup.org/HDF5/Tutor/fileorg.html">HDF5 group</a> contains:</p><ul><li>“<em>points</em>” dataset: x, y, z coordinates of each 3D point in the point cloud.</li><li>“<em>normals</em>” dataset: nx, ny, nz components of the unit normal associate to each point.</li><li>“<em>img</em>” dataset: the original MNIST image.</li><li>“<em>label</em>” attribute: the original MNIST label.</li></ul><p>In addition to train and test point clouds, the dataset also contains full_dataset_vectors.h5 that stores <em>4096-D</em> vectors obtained from voxelization of all the 3D point clouds and their randomly rotated copies with noise. The full_dataset_vectors.h5 is splitted into <em>4</em> groups:</p><pre>&gt;&gt;&gt; X_train = f[&quot;X_train&quot;][:]    # shape: (10000, 4096)<br>&gt;&gt;&gt; y_train = f[&quot;y_train&quot;][:]    # shape: (10000,)   <br>&gt;&gt;&gt; X_test  = f[&quot;X_test&quot;][:]     # shape: (2000, 4096) <br>&gt;&gt;&gt; y_test  = f[&quot;y_test&quot;][:]     # shape: (2000,)</pre><p>Here is an example to read a digit and store its group content in a tuple.</p><pre>&gt;&gt;&gt; with h5.File(&#39;train_point_clouds.h5&#39;, &#39;r&#39;) as f:<br>      # Reading digit at zeroth index    <br>      a = f[&quot;0&quot;]   <br>      # Storing group contents of digit a<br>      digit = (a[&quot;img&quot;][:], a[&quot;points&quot;][:], a.attrs[&quot;label&quot;])</pre><p>Let’s first visualize the contents stored in the tuple with matplotlib. The following code plots the first 15 images from the original 2D MNIST with their corresponding labels:</p><pre>&gt;&gt;&gt; # Plot some examples from original 2D-MNIST<br>&gt;&gt;&gt; fig, ax = plt.subplots(3,5, figsize=(12, 12), facecolor=&#39;w&#39;, edgecolor=&#39;k&#39;)</pre><pre>&gt;&gt;&gt; fig.subplots_adjust(hspace = .5, wspace=.2)</pre><pre>&gt;&gt;&gt; for ax, d in zip(axs.ravel(), digits):<br>      ax.imshow(d[0][:])<br>      ax.set_title(&quot;Digit: &quot; + str(d[2]))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*-KOJToUMVGIbuRCT-KLIpQ.png" /><figcaption>First 15 example images along with their labels from the 2D MNIST.</figcaption></figure><p>Before visualizing the 3D point clouds, let’s first discuss about Voxelization. <strong><em>Voxelization</em></strong> is the process of conversion of a geometric object from its continuous geometric representation into a set of voxels that best approximates the continuous object. The process mimics the scan-conversion process that rasterizes 2D geometric objects, and is also referred to as <a href="http://labs.cs.sunysb.edu/labs/projects/volume/Papers/glossary.html#voxelization:">3D scan-conversion</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/333/1*Bc26WD8NyH5_9Y7q72Y-9A.png" /><figcaption>Voxel Grid with a single voxel shaded. Source: <strong>[5]</strong></figcaption></figure><p>We use this process to fit an axis-aligned bounding box called the Voxel Grid around the point clouds and subdivide the grid into segments, assigning each point in the point cloud to one of the sub boxes (known as voxels, analogous to pixels). We split the grid into 16 segments along each axis resulting in a total of 4096 voxels, equivalent to the 4th level of an Octree.</p><pre>&gt;&gt;&gt; voxel_grid = VoxelGrid(digit, x_y_z = [16, 16, 16])</pre><p>The code above generates a voxel grid of 16 × 16 × 16 = 4096 voxels, with the structure attribute representing a 2D array, where each row represents a point in the original point cloud and each column represents the n_voxel where it lies with respect to [x_axis, y_axis, z_axis, global].</p><pre>&gt;&gt;&gt; voxel_grid.structure[0]</pre><pre><strong>array([ 5, 3, 7, 477])</strong></pre><p>The histogram shown below visualize the number of points present within each voxel. From the plot, it can be seen that there are a lot of empty voxels. This is due to the use of a cuboid bounding box to ensure that the Voxel Grid will divide the cloud in a similar way even when the point clouds are oriented to different directions.</p><pre>&gt;&gt;&gt; # Get the count of points within each voxel.<br>&gt;&gt;&gt; plt.title(&quot;DIGIT: &quot; + str(digits[0][-1]))<br>&gt;&gt;&gt; plt.xlabel(&quot;VOXEL&quot;)<br>&gt;&gt;&gt; plt.ylabel(&quot;POINTS INSIDE THE VOXEL&quot;)<br>&gt;&gt;&gt; count_plot(voxels[0].structure[:,-1])   # Check <a href="https://gist.github.com/imshashwataggarwal/5e27e7a1220b64cca2ab741033cedbe9#file-3dmnist-py-L47-L59">definition</a> here.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sjmc4lBUp9iuKQ7NfhM0zw.png" /><figcaption>Number of Points within each Voxel for a sample of digit 5.</figcaption></figure><p>We can visualize the Voxel Grid using the built-in helper function plot() defined in the file<em> plot3D.py</em> provided along with the dataset. This function displays the sliced spatial views of the Voxel Grid around the z-axis.</p><pre>&gt;&gt;&gt; # Visualizing the Voxel Grid sliced around the z-axis.</pre><pre>&gt;&gt;&gt; voxels[0].plot()<br>&gt;&gt;&gt; plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TPZ3Y4EFgitZtE9mhez5IQ.png" /><figcaption>Spatial View of the Voxel Grid of a sample of digit 5 sliced around the z-axis.</figcaption></figure><p>Now we visualize the 3D point clouds using an open-source 3D software, <a href="http://www.danielgm.net/cc/"><strong>CloudCompare</strong></a>. We save the Voxel Grid structure as the scalar fields of the original point clouds and render 3D images with CloudCompare.</p><blockquote>You can visualize the point clouds with any 3D software of your choice that supports point clouds and scalar fields!</blockquote><pre>&gt;&gt;&gt; # Save Voxel Grid Structure as the scalar field of Point Cloud.<br>&gt;&gt;&gt; cloud_vis = np.concatenate((digit[1], voxel_grid.structure), axis=1)</pre><pre>&gt;&gt;&gt; np.savetxt(&#39;Cloud Visualization - &#39; + str(digit[2]) + &#39;.txt&#39;, cloud_vis)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/1*MN3Lqta3X64MER1wxMctoA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*SFMQAhdyAsgO0gQ7VS8uBw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*VRnyqOlTlLadH1rIj2RIdQ.png" /><figcaption>Front View, Back View and Side View of 3D rendered image (from point clouds in CloudCompare) for the digit 5.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*bz4S1DmfbhFhZcYB-FEtgg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*oGk7FYD-S9X5c734w6qV9g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*_Sqm4E_Jt0JGCWMDoZnopg.png" /><figcaption>Front View, Back View and Side View of 3D rendered image (from point clouds in CloudCompare) for the digit 1.</figcaption></figure><p>At last, before moving on to the classification task, just for fun, let’s visualize the animation of 3D data slice by slice. Both the rows of the plot show the animation of slices along x, y, z-axis for the digits <em>5</em> and <em>0</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*yiV1bIQe7Ph-Iv9-O8Yr5g.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*9EHEmzk_OeDmXvtmW9mYFw.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*Ud0TFfgieIAZh2sqDRpEkA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*c4dO-Ei3kz7m8qlcsUKVwA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*c_OpS3G73YHbccaC9mPpPQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*QWOk4PCj8D_MXeNUi8hwCw.gif" /><figcaption>Slice by slice animation of 3D voxels around x, y and z-axis for the digits 5 (top) and 3 (bottom).</figcaption></figure><h4>Sklearn Machine Learning Classifiers</h4><p>We use the full_vectors.h5 dataset. You can use this or generate your own using this <a href="https://github.com/imshashwataggarwal/AI/blob/e51f942210de27edcdcf62138cc89c3c1a9cd1b7/Blogs/3D%20MNIST%20Image%20Classification/create_dataset.py#L1-L30">script</a>. In machine learning, there’s something called the <strong><em>“No Free Lunch” </em></strong>theorem that in a nutshell, states that no one algorithm works best for every problem. So we try many machine learning algorithms and choose the best suited to our problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*mcI34Fc0wZ0x-MbZ.jpg" /><figcaption><em>No Free Lunch!</em></figcaption></figure><p>Let’s start with the simplest yet powerful machine learning classifier — <strong><em>Logistic Regression</em></strong>:</p><h3>François Chollet on Twitter</h3><p>The ML research community has long been driven by the need to publish, which results in a stark, sometimes ridiculous bias towards complexity. Remember to ask: &quot;can we do this with k-means and logistic regression?</p><pre>&gt;&gt;&gt; reg = LogisticRegression()<br>&gt;&gt;&gt; reg.fit(X_train,y_train)<br>&gt;&gt;&gt; print(&quot;Accuracy: &quot;, reg.score(X_test,y_test))</pre><pre><strong>Accuracy:  0.582</strong></pre><p>Logistic Regression provides a decent baseline for other classifiers with an test-accuracy score of 58.2%. Next we move on to <strong><em>Decision Trees</em></strong><em>:</em></p><h3>r2d3.us on Twitter</h3><p>Machine learning explained in interactive visualizations (part 1) http://t.co/g75lLydMH9 #d3js #machinelearning</p><pre>&gt;&gt;&gt; dt = DecisionTreeClassifier()<br>&gt;&gt;&gt; dt.fit(X_train,y_train)<br>&gt;&gt;&gt; print(&quot;Accuracy: &quot;, dt.score(X_test,y_test))</pre><pre><strong>Accuracy:  0.4865</strong></pre><p>Decision Trees gives a test-accuracy of 48.65%, i.e. 10 points lower as compared to Logistic Regression. The performance of Decision Trees can possibly be improved with hyper-parameter tuning and grid-search. But here, we stick to the basics and try to get a rough estimate of the performance of the classifier. Moving further, let’s try <strong><em>Support Vector Machines</em></strong>:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F_PwhiWxHK8o%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D_PwhiWxHK8o&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F_PwhiWxHK8o%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/00926081a6aa1ba0474189cde30d0e3c/href">https://medium.com/media/00926081a6aa1ba0474189cde30d0e3c/href</a></iframe><pre>&gt;&gt;&gt; svm = LinearSVC()<br>&gt;&gt;&gt; svm.fit(X_train,y_train)<br>&gt;&gt;&gt; print(&quot;Accuracy: &quot;, svm.score(X_test,y_test))</pre><pre><strong>Accuracy:  0.557</strong></pre><p>We use linear SVMs instead of RBF or Poly kernel based SVM as they take a lot of time to train (<em>you may try training these SVM variants and compare their performance against other classifiers</em>). Linear SVMs perform similar to Logistic Regression with a test-accuracy score of 55.7%. Now, giving <strong><em>K Nearest Neighbors</em></strong> a shot!</p><h3>Kirk Borne on Twitter</h3><p>13 Great Articles About K-Nearest-Neighbors and Related #Algorithms: https://t.co/BToVsgNvT2 #abdsc #BigData #DataScience #MachineLearning</p><pre>&gt;&gt;&gt; knn = KNN()<br>&gt;&gt;&gt; knn.fit(X_train,y_train)<br>&gt;&gt;&gt; print(&quot;Accuracy: &quot;, knn.score(X_test,y_test))</pre><pre><strong>Accuracy:  0.5905</strong></pre><p>KNN performs best among all the previously tried classifiers with 59.05% test-score. Finally, let’s ensemble<em>;</em><strong><em> Random Forests:</em></strong></p><h3>r2d3.us on Twitter</h3><p>What does a data scientist &amp;amp; a vis designer do when they wander into a random forest? They make a random wreath! https://t.co/ppf0xl1k4V happy holidays! - @tonyhschu &amp;amp; @stephaniejyee</p><pre>&gt;&gt;&gt; rf = RandomForestClassifier(n_estimators=500)<br>&gt;&gt;&gt; rf.fit(X_train,y_train)<br>&gt;&gt;&gt; print(&quot;Accuracy: &quot;, rf.score(X_test,y_test))</pre><pre><strong>Accuracy:  0.685</strong></pre><p>Random Forests outperforms all other classifiers on the classification task. The table below reports the test-accuracy of each classifier on the 3D MNIST dataset. The confusion matrix plots shown below, provides us with the classification report summary of three classifiers namely, Logistic Regression, SVM and Random Forests. From these plots, we observe that most of the classifiers experience difficulty in classifying digits <em>5</em>, <em>6</em> and <em>9</em> correctly while find classifying digits like <em>0</em>, <em>1 </em>and <em>4</em> easy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*SBmPvAqYS7UwUa9Jy9IaXA.png" /><figcaption>Classification Report Summary for all Classifiers tested.</figcaption></figure><p>You can find the complete <a href="https://gist.github.com/imshashwataggarwal/5e27e7a1220b64cca2ab741033cedbe9">code</a> for ML-based empirical analysis <a href="https://github.com/imshashwataggarwal/AI/blob/master/Blogs/3D%20MNIST%20Image%20Classification/3D%20MNIST%20Image%20Classification.ipynb">here</a>. Although Random Forests performs best among the tried classifiers, the <strong>68.5% </strong>mark seems way behind its score on the 2D equivalent dataset. So the natural question that arrives is can we do better?</p><blockquote>Can We Do Better? Maybe Yes! <em>💡</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*8IAc26KZGsK7km_BAJ483g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*0hmfkh7rfDq1OQv72lajGQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*TXGW_3X-m0ryqWuh3wARfA.png" /><figcaption>Confusion Matrix for Logistic Regression (Left), SVM (Centre), and Random Forests (Right).</figcaption></figure><h4>Moving on to Convolutional Neural Networks</h4><p>Convolutional Neural Networks (CNN), have been immensely successful in classifying the 2D version of MNIST, with the current state-of-the-art model giving a high <strong>99.79%</strong> accuracy. So now, let’s see how well these CNN perform with the 3D equivalent of MNIST. We create a 4-layered CNN in keras with two dense layers at the top. For the complete definition of the model, look at the model() method. Since a sample in our dataset is a 4096-D voxel and CNN expects a 4D tensor of shape: (batch_size, height, width, input_channels), so we reshape our dataset into a 4D tensor: (-1, 16, 16, 16).</p><blockquote>We tried several other shapes such as (-1, 64, 64, 1), (-1, 64, 64, 3) but (-1, 16, 16, 16) gave the best results, so we stick with this.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a58700dbd938e6f84b708434e908cffe/href">https://medium.com/media/a58700dbd938e6f84b708434e908cffe/href</a></iframe><pre><strong>Output </strong><br>======</pre><pre>Epoch 1/30<br>3s - loss: 2.0299 - acc: 0.2922 - val_loss: 2.2644 - val_acc: 0.1960<br>Epoch 2/30<br>3s - loss: 1.4517 - acc: 0.4913 - val_loss: 2.0336 - val_acc: 0.4440<br>Epoch 3/30<br>3s - loss: 1.3081 - acc: 0.5364 - val_loss: 1.6669 - val_acc: 0.5140<br>Epoch 4/30<br>3s - loss: 1.2385 - acc: 0.5595 - val_loss: 1.4951 - val_acc: 0.5667<br>Epoch 5/30<br>3s - loss: 1.1959 - acc: 0.5799 - val_loss: 1.2812 - val_acc: 0.5813<br>Epoch 6/30<br>3s - loss: 1.1682 - acc: 0.5826 - val_loss: 1.1254 - val_acc: 0.6053<br>Epoch 7/30<br>3s - loss: 1.1552 - acc: 0.5909 - val_loss: 1.0595 - val_acc: 0.6240<br>Epoch 8/30<br>3s - loss: 1.1247 - acc: 0.6008 - val_loss: 0.9993 - val_acc: 0.6460<br>Epoch 9/30<br>3s - loss: 1.0981 - acc: 0.6142 - val_loss: 0.9978 - val_acc: 0.6313<br>Epoch 10/30<br>3s - loss: 1.0928 - acc: 0.6103 - val_loss: 0.9892 - val_acc: 0.6527<br>Epoch 11/30<br>3s - loss: 1.0770 - acc: 0.6202 - val_loss: 0.9940 - val_acc: 0.6387<br>Epoch 12/30<br>3s - loss: 1.0627 - acc: 0.6215 - val_loss: 0.9916 - val_acc: 0.6573<br>Epoch 13/30<br>3s - loss: 1.0704 - acc: 0.6239 - val_loss: 1.0423 - val_acc: 0.6400<br>Epoch 14/30<br>3s - loss: 1.0524 - acc: 0.6296 - val_loss: 0.9560 - val_acc: 0.6573<br>Epoch 15/30<br>3s - loss: 1.0331 - acc: 0.6320 - val_loss: 0.9504 - val_acc: 0.6540<br>Epoch 16/30<br>3s - loss: 1.0215 - acc: 0.6353 - val_loss: 0.9428 - val_acc: 0.6800<br>Epoch 17/30<br>3s - loss: 1.0052 - acc: 0.6461 - val_loss: 0.9492 - val_acc: 0.6633<br>Epoch 18/30<br>3s - loss: 1.0090 - acc: 0.6389 - val_loss: 0.9468 - val_acc: 0.6693<br>Epoch 19/30<br>3s - loss: 0.9957 - acc: 0.6520 - val_loss: 0.9322 - val_acc: 0.6700<br>Epoch 20/30</pre><pre>Epoch 00019: reducing learning rate to 0.000500000023749.</pre><pre>3s - loss: 0.9831 - acc: 0.6507 - val_loss: 0.9482 - val_acc: 0.6653<br>Epoch 21/30<br>3s - loss: 0.9643 - acc: 0.6636 - val_loss: 0.8976 - val_acc: 0.6767<br>Epoch 22/30<br>3s - loss: 0.9341 - acc: 0.6679 - val_loss: 0.8920 - val_acc: 0.6873<br>Epoch 23/30<br>3s - loss: 0.9078 - acc: 0.6785 - val_loss: 0.8755 - val_acc: 0.6933<br>Epoch 24/30<br>3s - loss: 0.9386 - acc: 0.6650 - val_loss: 0.8968 - val_acc: 0.6840<br>Epoch 25/30<br>3s - loss: 0.9130 - acc: 0.6792 - val_loss: 0.8872 - val_acc: 0.6900<br>Epoch 26/30<br>3s - loss: 0.8946 - acc: 0.6765 - val_loss: 0.8736 - val_acc: 0.6960<br>Epoch 27/30<br>3s - loss: 0.8997 - acc: 0.6785 - val_loss: 0.8668 - val_acc: 0.7060<br>Epoch 28/30<br>3s - loss: 0.8802 - acc: 0.6879 - val_loss: 0.8859 - val_acc: 0.6853<br>Epoch 29/30<br>3s - loss: 0.8877 - acc: 0.6890 - val_loss: 0.8732 - val_acc: 0.6967<br>Epoch 30/30<br>3s - loss: 0.8832 - acc: 0.6858 - val_loss: 0.8768 - val_acc: 0.6913</pre><pre><strong>Accuracy : 0.698</strong><br>Model Saved.</pre><h4>3D Convolutional Networks in Keras</h4><p>Finally, we move onto the main objective of this post (:P), 3D CNN. The 3D CNN model is similar to our 2D CNN model. For the complete definition of the model, check the model() method. Now, like with 2D CNN, the 3D CNN expects a 5D tensor of shape (batch_size, conv_dim1, conv_dim2, conv_dim3, input_channels). We reshape out input to a 5D tensor — (-1, 16, 16, 16, 3)and feed it to our 3D CNN.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6dc2511b4d19e21e7ab3fda0dfb9d702/href">https://medium.com/media/6dc2511b4d19e21e7ab3fda0dfb9d702/href</a></iframe><pre><strong>Output</strong><br>======</pre><pre>Epoch 1/30<br>11s- loss: 2.1194 - acc: 0.2912 - val_loss: 2.1434 - val_acc: 0.1660<br>Epoch 2/30<br>10s- loss: 1.3554 - acc: 0.5274 - val_loss: 1.8831 - val_acc: 0.4933<br>Epoch 3/30<br>10s- loss: 1.1520 - acc: 0.5954 - val_loss: 2.0278 - val_acc: 0.3427<br>Epoch 4/30<br>10s- loss: 1.0604 - acc: 0.6272 - val_loss: 1.3859 - val_acc: 0.5500<br>Epoch 5/30<br>10s- loss: 0.9991 - acc: 0.6448 - val_loss: 1.2405 - val_acc: 0.6000<br>Epoch 6/30<br>10s- loss: 0.9305 - acc: 0.6756 - val_loss: 1.0759 - val_acc: 0.6113<br>Epoch 7/30<br>10s- loss: 0.8790 - acc: 0.6939 - val_loss: 1.0644 - val_acc: 0.6673<br>Epoch 8/30<br>10s- loss: 0.8295 - acc: 0.7087 - val_loss: 0.8908 - val_acc: 0.6920<br>Epoch 9/30<br>10s- loss: 0.7648 - acc: 0.7289 - val_loss: 0.9673 - val_acc: 0.6940<br>Epoch 10/30<br>10s- loss: 0.7001 - acc: 0.7542 - val_loss: 0.8410 - val_acc: 0.7047<br>Epoch 11/30<br>10s- loss: 0.6485 - acc: 0.7719 - val_loss: 0.8781 - val_acc: 0.7133<br>Epoch 12/30<br>10s- loss: 0.5999 - acc: 0.7912 - val_loss: 0.8172 - val_acc: 0.7180<br>Epoch 13/30<br>10s- loss: 0.5375 - acc: 0.8147 - val_loss: 0.8366 - val_acc: 0.7207<br>Epoch 14/30<br>10s- loss: 0.4936 - acc: 0.8284 - val_loss: 0.8288 - val_acc: 0.7193<br>Epoch 15/30<br>10s- loss: 0.4337 - acc: 0.8494 - val_loss: 0.8528 - val_acc: 0.7320<br>Epoch 16/30<br>10s- loss: 0.4099 - acc: 0.8593 - val_loss: 1.0491 - val_acc: 0.6907<br>Epoch 17/30<br>10s- loss: 0.3601 - acc: 0.8764 - val_loss: 0.9005 - val_acc: 0.7333<br>Epoch 18/30<br>10s- loss: 0.3492 - acc: 0.8838 - val_loss: 0.9155 - val_acc: 0.7060<br>Epoch 19/30<br>10s- loss: 0.2939 - acc: 0.9000 - val_loss: 1.2862 - val_acc: 0.7007<br>Epoch 20/30<br>10s- loss: 0.2837 - acc: 0.9058 - val_loss: 0.9119 - val_acc: 0.7093<br>Epoch 21/30</pre><pre>Epoch 00020: reducing learning rate to 0.000500000023749.</pre><pre>10s- loss: 0.2786 - acc: 0.9104 - val_loss: 0.9305 - val_acc: 0.7287<br>Epoch 22/30<br>10s- loss: 0.1521 - acc: 0.9508 - val_loss: 1.0142 - val_acc: 0.7473<br>Epoch 23/30<br>10s- loss: 0.0944 - acc: 0.9699 - val_loss: 1.0704 - val_acc: 0.7300<br>Epoch 24/30<br>10s- loss: 0.0831 - acc: 0.9746 - val_loss: 1.1331 - val_acc: 0.7407<br>Epoch 25/30<br>10s- loss: 0.0691 - acc: 0.9773 - val_loss: 1.1615 - val_acc: 0.7393<br>Epoch 26/30</pre><pre>Epoch 00025: reducing learning rate to 0.000250000011874.</pre><pre>10s- loss: 0.0665 - acc: 0.9785 - val_loss: 1.1331 - val_acc: 0.7340<br>Epoch 27/30<br>10s- loss: 0.0468 - acc: 0.9856 - val_loss: 1.1230 - val_acc: 0.7367<br>Epoch 28/30<br>10s- loss: 0.0347 - acc: 0.9888 - val_loss: 1.1312 - val_acc: 0.7460<br>Epoch 29/30</pre><pre>Epoch 00028: reducing learning rate to 0.000125000005937.</pre><pre>10s- loss: 0.0283 - acc: 0.9919 - val_loss: 1.1361 - val_acc: 0.7340<br>Epoch 30/30<br>10s- loss: 0.0285 - acc: 0.9906 - val_loss: 1.1466 - val_acc: 0.7327</pre><pre><strong>Accuracy: 0.771</strong><br>Model Saved.</pre><p>The performance of 2D CNN is close to Random Forests with a test-score of 69.8%, but 3D CNN outperforms all other classifiers by a significant margin, giving a high 77.1% test-accuracy. Below we summarise the classification reports of 2D CNN and 3D CNN through their confusion matrix plots and learning curves respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aLkwzvfTBPVa9uzM9XiXfg.png" /><figcaption>Confusion Matrix for 2D CNNs</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xvVW-aKnOuUw_OGaDWMECg.png" /><figcaption>Confusion Matrix for 3D CNNs</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6SFci73HKkVB_drT0cSndg.png" /><figcaption>Training Accuracy for 2D CNN (blue) and 3D CNN (orange).</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N0LfeN-k8F7dbAj7jkpCJQ.png" /><figcaption>Training Loss for 2D CNN (blue) and 3D CNN (orange).</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mOG1740xhW21mqLuU-8T9w.png" /><figcaption>Validation Accuracy for 2D CNN (blue) and 3D CNN (orange).</figcaption></figure><h4><strong>More 3D Datasets</strong></h4><p>In this blog post, we experimented with 3D MNIST dataset, that proved to be a good benchmark for starting with 3D Datasets. Here is a list of few more 3D Datasets that are worth playing with:</p><p><a href="http://pie.med.utoronto.ca/TEE/TEE_content/assets/video/3Dtee/Epiq7/3DCropping/AutoCrop/index.html">Manipulation of 3D Datasets Video - Cropping 3D Datasets - Philips Epiq 7 - Auto Crop</a></p><ol><li><strong>Data Science Bowl </strong>2017, available <a href="https://www.kaggle.com/c/data-science-bowl-2017/data">here</a>.</li><li>The <strong>Joint 2D-3D-Semantic (2D-3D-S) Dataset</strong>, available <a href="http://3dsemantics.stanford.edu/">here</a>.</li><li>The <strong>Street View Image, Pose, and 3D Cities Dataset</strong>, available <a href="https://github.com/amir32002/3D_Street_View">here</a>, <a href="http://3drepresentation.stanford.edu/">Project page</a>.</li><li>The <strong>Stanford Online Products dataset</strong>, available <a href="/service/ftp://cs.stanford.edu/cs/cvgl/Stanford_Online_Products.zip">here</a>.</li><li>The <strong>ObjectNet3D Dataset</strong>, available <a href="http://cvgl.stanford.edu/projects/objectnet3d/">here</a>.</li><li>The <strong>Stanford Drone Dataset</strong>, available <a href="http://cvgl.stanford.edu/projects/uav_data/">here</a>.</li><li><a href="http://cvgl.stanford.edu/resources.html"><strong>More</strong></a><strong> </strong>Datasets.</li></ol><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FMqcZYw8Tgpc%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DMqcZYw8Tgpc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FMqcZYw8Tgpc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d2ec3c67c6dc043b22febde2844c601/href">https://medium.com/media/2d2ec3c67c6dc043b22febde2844c601/href</a></iframe><h4>References</h4><ol><li>The MNIST database of handwritten digits. Y LeCun, C Cortes. 1998.</li><li>ImageNet classiﬁcation with deep convolutional neural networks. A. Krizhevsky and I. Sutskever and G. Hinton. NIPS, 2012.</li><li>Regularization of neural networks using dropconnect. L. Wan and M. Zeiler and S. Zhang and Y. L. Cun and R. Fergus. ICML, 2013.</li><li>3D MNIST Dataset. <a href="https://www.kaggle.com/daavoo/3d-mnist/data">https://www.kaggle.com/daavoo/3d-mnist/data</a>.</li><li>Voxel. <a href="https://en.wikipedia.org/wiki/Voxel#/media/File:Voxels.svg">https://en.wikipedia.org/wiki/Voxel#/media/File:Voxels.svg</a>.</li><li>3D convolutional neural networks for human action recognition. S. Ji and W. Xu and M. Yang and K. Yu. ICML, 2010.</li><li>HDF5 File Format. <a href="https://support.hdfgroup.org/HDF5/whatishdf5.html">https://support.hdfgroup.org/HDF5/whatishdf5.html</a></li><li>Scikit-learn: Machine Learning in Python. Pedregosa et al. JMLR 12, 2011.</li><li>Keras, <a href="https://github.com/fchollet/keras%7D%7D">https://github.com/fchollet/keras</a>. François Chollet. GitHub, 2015.</li><li>Stanford Computational Vision and Geometry Lab, <a href="http://cvgl.stanford.edu/resources.html">http://cvgl.stanford.edu/resources.html</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b922a3d07334" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>