下面是一个应该运行的示例,显示了两种不同的嵌入。请注意,您需要转到“投影仪”选项卡。有时它不会自动打开。
log_dir='./logs'
embeddings=np.random.randint(1,100,(400,6))
labels=[1,2,3,4]*100
with open(f'{log_dir}/metadata.tsv', "w") as file:
for label in labels:
file.write(f'{label}\n')
with open(f'{log_dir}/metadata2.tsv', "w") as file:
for label in labels:
file.write(f'{label}\n')
os.makedirs(log_dir,exist_ok=True)
embeddings1=tf.Variable(embeddings,name='var1')
embeddings2=tf.Variable(embeddings,name='var2')
checkpoint=tf.train.Checkpoint(var1=embeddings1,var2=embeddings2)
checkpoint.save(log_dir+'/var.ckpt')
config=projector.ProjectorConfig()
emb1=config.embeddings.add()
emb1.tensor_name='var1'+'/.ATTRIBUTES/VARIABLE_VALUE'
emb1.metadata_path='metadata.tsv'
emb2=config.embeddings.add()
emb2.tensor_name='var2'+'/.ATTRIBUTES/VARIABLE_VALUE'
emb2.metadata_path='metadata2.tsv'
projector.visualize_embeddings(log_dir, config)
%load_ext tensorboard
%tensorboard --logdir ./logs/