Visualizing Image Feature Vectors through TensorBoard

Introduction

Sometime you may want to see and show image feature vectors visually. TensorBoard is very good tool for such purpose.

This post describes how to visualize image feature vectors and image embeddings through TensorBoard

The content is different from official document TensorBoard: Embedding Visualization. Even checkpoint file is not required.

Goal

Visualizing your own image feature vectors.

Things necessary

  • Images
  • Sprite image of the input images
  • Image feature extractor / Image feature vector
  • Config file
  • TensorFlow / TensorBoard (tensorflow:1.8.0 and tensorflow-hub:0.1.0 are used here)

Images

I collected 2,500 animal images through Google image search. File path of the images are like ./images/img_0001.jpg — ./images/img_2500.jpg.

Sprite image

It is super easy to generate a sprite image using ImageMagick.

$ montage images/img_*.jpg -tile 50x50 -geometry 50x50! sprite.jpg

Feature extraction

feature_extraction.py

Simpler version is below:

simple_feature_extraction.py

Not only MobileNet v2, also other models, like Inception and Resnet, are available in TensorFlow Hub: Image Modules.

Using the script above, feature_vecs.tsv is generated.

Config file

projector_config.pbtxt

TensorBoard

Run tensorboard at the directory of projector_config.pbtxt.

$ tensorboard --logdir .

Then, go to http://localhost:6006/#projector.

Congrats!

PCA and t-SNE are available for the dimension reduction. Have fun!

(If you cannot see your feature space, reload the page.)

--

--

Director of Engineering/Machine Learning Engineer at Mercari.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store