title: Visualize the output of Vgg16 model by TSNE plot?
body: <p>I need to visualize the output of Vgg16 model which classify 14 different classes. 
  I load the trained model and I did replace the classifier layer with the identity() layer but it doesn't categorize the output. </p>
  
  <p>Here is the snippet:
  the number of samples here is 1000 images.</p>
  
  <pre><code>epoch = 800
  PATH = 'vgg16_epoch{}.pth'.format(epoch)
  checkpoint = torch.load(PATH)
  model.load_state_dict(checkpoint['model_state_dict'])
  optimizer.load_state_dict(checkpoint['optimizer_state_dict'])
  epoch = checkpoint['epoch']
  
  class Identity(nn.Module):
      def __init__(self):
          super(Identity, self).__init__()
  
      def forward(self, x):
          return x
  
  model.classifier._modules['6'] = Identity()
  model.eval()
  logits_list = numpy.empty((0,4096))  
  targets = []
  
  
  with torch.no_grad():
      for step, (t_image, target, classess, image_path) in enumerate(test_loader):
  
          t_image = t_image.cuda()
          target = target.cuda()
          target = target.data.cpu().numpy()
          targets.append(target)
  
          logits = model(t_image)
          print(logits.shape)
  
          logits = logits.data.cpu().numpy()
          print(logits.shape)
          logits_list = numpy.append(logits_list, logits, axis=0)     
          print(logits_list.shape)
  
  
  tsne = TSNE(n_components=2, verbose=1, perplexity=10, n_iter=1000) 
  tsne_results = tsne.fit_transform(logits_list)   
  
   target_ids = range(len(targets))
  
  plt.scatter(tsne_results[:,0],tsne_results[:,1],c = target_ids ,cmap=plt.cm.get_cmap("jet", 14))
  plt.colorbar(ticks=range(14))
  plt.legend()
  plt.show()
  </code></pre>
  
  <p>here is what this script has been produced: I am not sure why I have all colors for each cluster! 
  <a href="https://i.stack.imgur.com/2EJee.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2EJee.png" alt="enter image description here"></a></p>