keras能够使用keras.callbacks.TensorBoard以张量板可编码格式导出其中一些训练数据
但是,它不支持在tensorboard中嵌入可视化.
有没有解决的办法?
找到了解决方案:
import os import keras import tensorflow ROOT_DIR = '/tmp/tfboard' os.makedirs(ROOT_DIR, exist_ok=True) OUTPUT_MODEL_FILE_NAME = os.path.join(ROOT_DIR,'tf.ckpt') # get the keras model model = get_model() # get the tensor name from the embedding layer tensor_name = next(filter(lambda x: x.name == 'embedding', model.layers)).W.name # the vocabulary metadata_file_name = os.path.join(ROOT_DIR,tensor_name) embedding_df = get_embedding() embedding_df.to_csv(metadata_file_name, header=False, columns=[]) saver = tensorflow.train.Saver() saver.save(keras.backend.get_session(), OUTPUT_MODEL_FILE_NAME) summary_writer = tensorflow.train.SummaryWriter(ROOT_DIR) config = tensorflow.contrib.tensorboard.plugins.projector.ProjectorConfig() embedding = config.embeddings.add() embedding.tensor_name = tensor_name embedding.metadata_path = metadata_file_name tensorflow.contrib.tensorboard.plugins.projector.visualize_embeddings(summary_writer, config)
有此功能的pull请求 - https://github.com/fchollet/keras/pull/5247回调扩展为特定嵌入层创建可视化.