Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

你好关于tsne可视化,提供的代码 这块的代码不对吧? #24

Open
yhl2018 opened this issue May 13, 2024 · 0 comments
Open

Comments

@yhl2018
Copy link

yhl2018 commented May 13, 2024

for batch_idx, (input1, input2, label1, label2) in enumerate(trainloader):
labels = torch.cat((label1, label2), 0)
z1 = torch.ones(label1.shape)
z2 = torch.zeros(label2.shape)
z = torch.cat((z1, z2), 0)
print(batch_idx)
input1 = Variable(input1.cuda())
input2 = Variable(input2.cuda())

      a = labels.unique()
      for i in range(len(a)):
        for j in range(len(labels)):
          if labels[j] == a[i]:
              labels[j] = i
      #print(labels)
      data_time.update(time.time() - end)
      out = torch.cat((input1, input2), 0)

      tsne = manifold.TSNE(n_components=2, init='pca', random_state=0)
      X_tsne = tsne.fit_transform(out.detach().cpu().numpy())
      plot_embedding(X_tsne, labels, z)
      plt.savefig(osp.join('save_tsne', 'tsne_{}.jpg'.format(batch_idx)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant