Created
July 19, 2017 05:17
-
-
Save TomHortons/8afcf86ee53e073ad21b7d3d0eb4a9fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.manifold import TSNE | |
tsne = TSNE( | |
n_components=2, | |
init='random', # pca | |
random_state=101, | |
method='barnes_hut', | |
n_iter=500, | |
verbose=2 | |
).fit_transform(img_mat) | |
from matplotlib.offsetbox import OffsetImage, AnnotationBbox | |
def imscatter(x, y, images, ax=None, zoom=0.1): | |
ax = plt.gca() | |
images = [OffsetImage(image, zoom=zoom) for image in images] | |
artists = [] | |
for x0, y0, im0 in zip(x, y, images): | |
ab = AnnotationBbox(im0, (x0, y0), xycoords='data', frameon=False) | |
artists.append(ax.add_artist(ab)) | |
ax.update_datalim(np.column_stack([x, y])) | |
ax.autoscale() | |
#return artists | |
nimgs = 500 | |
plt.figure(figsize=(13,10)) | |
imscatter(tsne[0:nimgs,0], tsne[0:nimgs,1], [plt.imread(image_paths[i]) for i in range(nimgs)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment