Skip to content

Instantly share code, notes, and snippets.

@TomHortons
Created July 19, 2017 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TomHortons/8afcf86ee53e073ad21b7d3d0eb4a9fa to your computer and use it in GitHub Desktop.
Save TomHortons/8afcf86ee53e073ad21b7d3d0eb4a9fa to your computer and use it in GitHub Desktop.
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