Compressed Sensing for Image Classification

Classifying MNIST digits directly from compressive measurements, using random and learned sensing matrices.

Code on GitHub

Overview

Compressed sensing is a technique used in image acquisition, where special camera hardware captures images in a compressed form. The captured measurements can be as small as 10% of the original image size. This helps in low-resource compute environments, as it requires less power and storage. The compressed measurements can also be used directly for image classification, with an image-processing technique or a small machine-learning model, which further reduces the compute overhead of larger vision models that use full images.

In this work, we perform image classification on the MNIST dataset with 10 classes using compressive measurements. This involves sampling the image with a sensing matrix and then using the cluster centres computed on the training data to run a k-means-based algorithm for the final classification. We achieve a classification accuracy of 75% with this traditional approach. We further learn the sensing matrix on the training data, with the objective of maximizing the relative distance between the cluster centres, which increases the accuracy to 87%. We also implement the GMLC (smashed-filter-based) algorithm, which first computes the most likely rotation angle and then performs the final classification, giving an impressive accuracy of 70%. We conclude by generating a video of MNIST digits and testing our algorithm on real-time classification: it classified the test images in a 30 fps video with an accuracy of 84%.

Index terms: compressed sensing, smashed filter, k-means, GMLC, sensing matrix, deep learning

DCT coefficients and analysis

The following figure shows the clusters of DCT coefficients for the 10 classes. We also ran a simple k-means algorithm on these clusters, but the test-set accuracy was only about 20%. This is clearly not a good accuracy, and it motivates the need for better classification methods.

Clusters of DCT coefficients for the 10 MNIST classes
Clusters of DCT coefficients for different classes on the train split

Image and feature clusters of measurements

The following two figures show the clusters formed by the image pixels and by only 390 measurements obtained with a learned sensing matrix, trained with the objective of maximizing the inter-cluster distance. Even with only 50% of the original image size, a smart choice of sensing matrix preserves almost the same information.

Clusters of image pixels for the 10 MNIST classes
Clusters of compressive measurements obtained with the learned sensing matrix
Left: clusters of image pixels for the 10 classes. Right: clusters of measurements obtained with the sensing matrix.

Classification accuracy for 3 classes

We started with image classification on 3 classes of the MNIST dataset, using compressive measurements obtained with a random sensing matrix. The accuracy reaches almost 95% with a number of measurements that is only about 7% of the number of pixels in the image. The following plot shows the classification accuracy vs. the number of measurements.

Classification accuracy vs. number of measurements for 3 classes
Classification accuracy vs. number of measurements for 3 classes

Manifold cluster centre distances

The following plot shows the mean distance between cluster centroids of different classes as a function of the number of measurements. The inter-cluster distance increases with the number of measurements, which is a good sign: it suggests that more measurements will help to improve classification accuracy.

Inter-centroid distance vs. number of measurements
Inter-centroid distance vs. number of measurements

Classification using a random sensing matrix

We used a sensing matrix initialized with samples drawn from a standard normal distribution, and used it to classify all 10 classes of the MNIST dataset. The following plot shows the classification accuracy as a function of the number of measurements.

Classification accuracy vs. number of measurements with a random sensing matrix
Classification accuracy vs. number of measurements (random sensing matrix)

Learning the sensing matrix from data

After the elementary experiments with a random sensing matrix, we used data to learn the sensing matrix, with the objective of maximizing the inter-cluster distance by defining a kernel per class. The exact mathematical formulation is as follows:

  1. The kernel function is defined as:

    \[K_{c}(f_{\theta}(x), e_{c}) = \exp\left(-\frac{\frac{1}{n}\lVert W_{c}f_{\theta}(x) - e_{c}\rVert_{2}^{2}}{2\sigma^{2}}\right)\]
  2. The correct class label should have the largest kernel value. Thus, at test time the class label is evaluated as:

    \[\arg \max_{c} K_{c}(f_{\theta}(x), e_{c})\]
  3. The sensing matrix was learned to give the correct kernel values, using the following binary cross-entropy objective:

    \[L(x, y) = -\sum_{c} \left[ y_{c}\log K_{c} + (1 - y_{c})\log (1 - K_{c}) \right]\]

Classification accuracy comparisons

We then compared the classification accuracy of the random and learned sensing matrices for numbers of measurements in the range 10–400. The classification accuracy is consistently better with the learned sensing matrix than with the random sensing matrix, as the following plot shows.

Classification accuracy of the random and learned sensing matrices vs. number of measurements
Classification accuracy of the random vs. learned sensing matrix

Classification accuracy after random rotations

We defined a function that rotates an input image by an angle chosen randomly in 0–360°, and then implemented the smashed-filter-based GMLC algorithm, which first computes the correct angle of rotation and then estimates the correct class. The same experiment was repeated for the learned matrix. Once we take enough samples, the classification accuracy of the random sensing matrix is better than that of the learned one. The plot is as follows:

Classification accuracy vs. number of samples under random rotations
Accuracy vs. number of samples under random rotations

Classification accuracy after adding noise

We added random normal noise to the data, since no sensor has perfect acquisition. The classification accuracy is better for the learned sensing matrix even after adding a lot of noise. The results for various noise variances, for both the random and learned sensing matrices, are as follows:

Classification accuracy vs. noise variance with the random sensing matrix
Classification accuracy vs. noise variance with the learned sensing matrix
Left: random sensing matrix. Right: learned sensing matrix.

Mutual coherence of the sensing matrices

The mutual coherence of a matrix is the largest absolute normalized inner product between any two distinct columns of the matrix. A smaller coherence allows good reconstruction of signals with larger sparsity, so we want the mutual coherence to be as small as possible. The coherence values are better for the random matrix, so a randomly initialized sensing matrix will reconstruct images better than the learned one. The following plot compares the coherence of the random and learned matrices for different numbers of measurements:

Mutual coherence of the random and learned sensing matrices vs. number of measurements
Mutual coherence of the random and learned sensing matrices

Real-time classification in video

We created a video of 12 randomly sampled images from the test split at 30 fps, and then used our model to predict, in real time, the labels of the digits displayed in the video, with both the random and the learned sensing matrix. The videos, with the predictions displayed on them, are in the Videos folder of the GitHub repository. The classification results were as follows:

  1. Random sensing matrix: 9/12 correct predictions
  2. Learned sensing matrix: 10/12 correct predictions

References

[1] M. A. Davenport, M. F. Duarte, M. B. Wakin, J. N. Laska, D. Takhar, K. F. Kelly, and R. G. Baraniuk, “The smashed filter for compressive classification and target recognition,” in Computational Imaging V, vol. 6498, pp. 142–153, SPIE, 2007.