omoindrot / tensorflow-triplet-loss

Implementation of triplet loss in TensorFlow
https://omoindrot.github.io/triplet-loss
MIT License
1.12k stars 284 forks source link

How to use the projector? #29

Open FSet89 opened 5 years ago

FSet89 commented 5 years ago

During training, the projector shows some points in the PCA space. Every point has the same color. What do they represent? What can I infer about the training process from this graph?

omoindrot commented 5 years ago

Normally you should be able to color by label if you provided the labels.

For MNIST, you will have one color for each digit.

Maybe this post can help your understanding? https://stackoverflow.com/questions/40849116/how-to-use-tensorboard-embedding-projector

FSet89 commented 5 years ago

Thank you. Can you point me out where in your code you add the images for the projector summary?

batrlatom commented 5 years ago

It is in the visualize_embeddings.py I think it is here


embedding.sprite.image_path = pathlib.Path(args.sprite_filename).name
    embedding.sprite.single_image_dim.extend([28, 28])
omoindrot commented 5 years ago

So it's in the metadata tsv file that you need to save: https://github.com/omoindrot/tensorflow-triplet-loss/blob/fc698369bb6c9acdc9f0e9e1ea00de0ddf782f12/visualize_embeddings.py#L83-L90

    # Specify where you find the metadata
    # Save the metadata file needed for Tensorboard projector
    metadata_filename = "mnist_metadata.tsv"
    with open(os.path.join(eval_dir, metadata_filename), 'w') as f:
        for i in range(params.eval_size):
            c = labels[i]
            f.write('{}\n'.format(c))
    embedding.metadata_path = metadata_filename

If you want to visualize other colors, you can add it in the tsv file as a new column like this:

    metadata_filename = "mnist_metadata.tsv"
    with open(os.path.join(eval_dir, metadata_filename), 'w') as f:
        f.write("label\tother")
        for i in range(params.eval_size):
            c = labels[I]
            other = c % 2
            f.write('{}\t{}\n'.format(c, other))
    embedding.metadata_path = metadata_filename