def _add_embedding_config()

in python/mxboard/utils.py [0:0]


def _add_embedding_config(file_path, data_dir, has_metadata=False, label_img_shape=None):
    """Creates a config file used by the embedding projector.
    Adapted from the TensorFlow function `visualize_embeddings()` at
    https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/tensorboard/plugins/projector/__init__.py"""
    with open(os.path.join(file_path, 'projector_config.pbtxt'), 'a') as f:
        s = 'embeddings {\n'
        s += 'tensor_name: "{}"\n'.format(data_dir)
        s += 'tensor_path: "{}"\n'.format(os.path.join(data_dir, 'tensors.tsv'))
        if has_metadata:
            s += 'metadata_path: "{}"\n'.format(os.path.join(data_dir, 'metadata.tsv'))
        if label_img_shape is not None:
            if len(label_img_shape) != 4:
                logging.warning('expected 4D sprite image in the format NCHW, while received image'
                                ' ndim=%d, skipping saving sprite'
                                ' image info', len(label_img_shape))
            else:
                s += 'sprite {\n'
                s += 'image_path: "{}"\n'.format(os.path.join(data_dir, 'sprite.png'))
                s += 'single_image_dim: {}\n'.format(label_img_shape[3])
                s += 'single_image_dim: {}\n'.format(label_img_shape[2])
                s += '}\n'
        s += '}\n'
        f.write(s)