lhoyer / DAFormer

[CVPR22] Official Implementation of DAFormer: Improving Network Architectures and Training Strategies for Domain-Adaptive Semantic Segmentation
Other
466 stars 91 forks source link

More detail about T-SNE visual #88

Open yuheyuan opened 6 months ago

yuheyuan commented 6 months ago

image I try use T-sne to visual the features. But I meet some problems.

There are a total of 500 verified images on the citycapes dataset. I use the model to predict the image, keep the final output features, and upsample to the image label size. Then feature visualization. But I failed because the size is very large and the visualization failed or visualization didn't work out well like your papaers. So I'd like to ask you about details of your use of tsne. Do you save 500 images features for visual? I have tried many methods, but all fall.

here's my code


tsne_features = []
tsne_labels = []
for index, batch in enumerate(testloader):
      images, labels, = batch

      outputs = model(images).squeeze(0).permute(1,2,0).reshape(-1, 10)  # it's feaures size is very big
      tsne_features.append(outputs)
      tsne_labels.append(labels.squeeze(0).reshape(-1))

features = np.concatenate(tsne_features, axix = 0)
labels = np.concatenate(tsne_labels, axix = 0)

from tsnecuda import TSNE
from sklearn.decomposition imort PCA

embeddings = TSNE(n_components = 2, perplexity=15, learning_rate = 10).fit_transform(features)

plt.figure(figsize=(10, 8))
scatter = plt.scatter(embedding[:0], embeddings[:,1], c= labels, camp="tab20", alph=0.6, edgecolors='w', linewidths=0.5)
plt.colobar(scatter)
plt.title("t-sne visual")
plt.show()
wqh011128 commented 1 month ago

图像我尝试使用 T-sne 来可视化这些功能。但我遇到了一些问题。

citycapes 数据集上共有 500 张经过验证的图像。我使用该模型来预测图像,保留最终输出特征,并上采样到图像标签大小。然后是特征可视化。但我失败了,因为大小非常大,可视化失败,或者可视化效果不如你的爸爸。所以我想问你一下你使用 tsne 的细节。您是否保存 500 张图像特征以进行视觉?我尝试了很多方法,但都失败了。

这是我的代码

tsne_features = []
tsne_labels = []
for index, batch in enumerate(testloader):
      images, labels, = batch

      outputs = model(images).squeeze(0).permute(1,2,0).reshape(-1, 10)  # it's feaures size is very big
      tsne_features.append(outputs)
      tsne_labels.append(labels.squeeze(0).reshape(-1))

features = np.concatenate(tsne_features, axix = 0)
labels = np.concatenate(tsne_labels, axix = 0)

from tsnecuda import TSNE
from sklearn.decomposition imort PCA

embeddings = TSNE(n_components = 2, perplexity=15, learning_rate = 10).fit_transform(features)

plt.figure(figsize=(10, 8))
scatter = plt.scatter(embedding[:0], embeddings[:,1], c= labels, camp="tab20", alph=0.6, edgecolors='w', linewidths=0.5)
plt.colobar(scatter)
plt.title("t-sne visual")
plt.show()

你好,请问你实现tsne可视化了吗,我也遇到这样的问题