16

600X t-SNE speedup with RAPIDS

 4 years ago
source link: https://mc.ai/600x-t-sne-speedup-with-rapids/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

600X t-SNE speedup with RAPIDS

GPU accelerationsare commonly associated with Deep Learning. GPUs power the training of Convolutional Neural Networks for Vision tasks or Transformer models for NLP. They do this through parallel computation , making them much faster for certain tasks vs. CPUs.

RAPIDS is expanding the utilization of GPUs by bringing traditional Machine Learning and Data Science algorithms, such as t-SNE or XGBoost, to GPUs.

Hardware: This experiment was run on the Data Science PC by Digital Storm

t-SNE is an algorithm for visualizing high-dimensional data. Shown above is an example of transforming the 512-dimensional vectors from intermediate CNN activations into 2-dimensional vectors. Each image in the CIFAR-10 dataset is passed through the image classifier and the activations right before the final classification layer are added to an array for visualization. This is done with the following line of code:

from tensorflow.keras.models import Modelintermediate_layer_model = Model(inputs = model.input, 
 outputs = model.get_layer('VisualizationLayer').output)

t-SNE visualization is great for gaining intuition about the decision space. Another approach to this might be to use a confusion matrix. The t-SNE visualization shows errors such as the overlap between cars and airplanes. Whereas a confusion matrix would simply tell us something like ‘8’ cars have been misclassified as airplanes, the t-SNE visualization gives more information about what is happening here. We see that at least the misclassified cars are on the fringe of the airplane boundary, we might be able to solve this problem with some label smoothing / data augmentation.

Gaining intuition about our models is very useful for this kind of EDA (exploratory data analysis). This can help inform data-level decisions such as identifying the impact of class imbalance, data augmentation, or utility of gathering more data. This can also help compare loss functions with another.

In “GAN-based Synthetic Medical Image Augmentation for increased CNN Performance in Liver Lesion Classification”, Frid-adar et al. use t-SNE visualizations to show how adding GAN-generated data improves the decision boundaries for Medical Image classification (notice the improved disentanglement of the blue class in figure b compared to a).

In “Improving Adversarial Robustness via Guided Complement Entropy” by Chen et al. They show how their improvement on the cross-entropy loss function results in a smoother decision boundary with less overlap (compare the figure on the right to the figure on the left). They use this visualization to illustrate how their improved decision boundaries provide adversarial attack defense.

Another interesting application of t-SNE In the “Do’s and Dont’s of using t-SNE to Understand Vision Models” presented by Laurens van der Maaten at CVPR 2018

New vs. Old

This example demonstrates > 600X speedup on t-SNE using RAPIDS vs. Sklearn

This example is running the Barnes-Hut (n log n) version of t-SNE on 50,000 CIFAR-10 images that have been processed through an image classifier (trained to 79% accuracy) to 512-dimensional vectors. The t-SNE algorithm converts these 512-d vectors to 2-d for visualization.

1918 seconds (~30 minutes) (Sklearn)

from sklearn.manifold import TSNE
sklearn_embedded = TSNE(n_components=2).fit_transform(embeddings)

3 seconds (RAPIDS cuml)

from cuml.manifold import TSNE as cumlTSNE
tsne = cumlTSNE(n_components=2, method='barnes_hut')
tsne_embedding = tsne.fit_transform(embeddings)

Hardware: This experiment was run on the Data Science PC by Digital Storm

The Impact of RAPIDS

The t-SNE speedup enabled by RAPIDS makes high-dimensional data visualization much more practical. Embedding the 50K CIFAR-10 vectors took 30 minutes on the CPU implementation, trying to embed the 1.2 million ImageNet dataset would take at least 12 hours by extension if the t-SNE algorithm had O(n) time complexity (although the latter log n of the barnes-hut algorithm would be largely negligible at this scale).

Powered by RAPIDS, t-SNE visualization can enable visualization of the entire ImageNet dataset ( explored in t-SNE-CUDA by Chan et al. ).

GPU speedups on these kinds of vector representations are also enormously useful for Image similarity / retrieval applications. One of the best approach for finding the most semantically similar image from a large image database is to compare the intermediate activations of an image classifier. This results in comparing a large set of k-dimensional vector embeddings from the classifier. RAPIDS can dramatically speed up this kind of operations for clustering algorithms such as K-Means.

t-SNE is a great technique to gain insight about datasets and the intermediate representations constructed by neural networks. RAPIDS is helping power t-SNE to new heights through GPU-acceleration, enabling a much larger volume of data to be visualized with this algorithm.

Thanks for reading! If you found this article interesting, you may also enjoy this video walking through the experiment step-by-step from the NGC docker container to setup the RAPIDS libraries to the final t-SNE visualization!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK