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
fig.canvas.mpl_connect('motion_notify_event', hover) |
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
def hover(event): | |
# if the mouse is over the scatter points | |
if line.contains(event)[0]: | |
# find out the index within the array from the event | |
ind, = line.contains(event)[1]["ind"] | |
# get the figure size | |
w,h = fig.get_size_inches()*fig.dpi | |
ws = (event.x > w/2.)*-1 + (event.x <= w/2.) | |
hs = (event.y > h/2.)*-1 + (event.y <= h/2.) | |
# if event occurs in the top or right quadrant of the figure, |
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
import matplotlib.pyplot as plt | |
from matplotlib.offsetbox import OffsetImage, AnnotationBbox | |
import numpy as np; np.random.seed(42) | |
# Generate data x, y for scatter and an array of images. | |
x = np.arange(20) | |
y = np.random.rand(len(x)) | |
arr = np.empty((len(x),10,10)) | |
for i in range(len(x)): | |
f = np.random.rand(5,5) |
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
# create the annotations box | |
im = OffsetImage(arr[0,:,:], zoom=5) | |
xybox=(50., 50.) | |
ab = AnnotationBbox(im, (50,50), xybox=xybox, xycoords='data', | |
boxcoords="offset points", pad=0.3, arrowprops=dict(arrowstyle="->")) | |
# add it to the axes and make it visible | |
ax.add_artist(ab) | |
ab.set_visible(True) |
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
# create figure and plot scatter | |
fig = plt.figure() | |
ax = fig.add_subplot(111) | |
line, = ax.plot(x,y, ls="", marker="o") |
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
import matplotlib.pyplot as plt | |
from matplotlib.offsetbox import OffsetImage, AnnotationBbox | |
import numpy as np; np.random.seed(42) | |
# Generate data x, y for scatter and an array of images. | |
x = np.arange(20) | |
y = np.random.rand(len(x)) | |
arr = np.empty((len(x),10,10)) | |
for i in range(len(x)): | |
f = np.random.rand(5,5) |
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
import matplotlib.pyplot as plt | |
from matplotlib.offsetbox import OffsetImage, AnnotationBbox | |
import numpy as np; np.random.seed(42) | |
# Generate data x, y for scatter and an array of images. | |
x = np.arange(20) | |
y = np.random.rand(len(x)) | |
arr = np.empty((len(x),10,10)) | |
for i in range(len(x)): | |
f = np.random.rand(5,5) |
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
# -*- coding: utf-8 -*- | |
""" | |
@author: Mortis | |
""" | |
#%% Read and prepare data | |
import os | |
import keras |
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
import keras.backend as K | |
import cv2 | |
from keras.preprocessing.image import array_to_img | |
from scipy.misc import imsave | |
label_name = {0:'Cat',1:'Dog'} | |
index = 8 | |
img = test_data[index] | |
img_show=array_to_img(img) | |
imsave('Image_{}.png'.format(index),img_show) | |
img=img.reshape(-1,128,128,3) |
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
#%% t-SNE | |
from keras.models import Model | |
from sklearn.manifold import TSNE | |
def plot_tSNE(model,layername,input_data,input_label,modelname='Model',label_name=['label one']): | |
batch_size=64 | |
intermediate_layer_model = Model(inputs=model.input, | |
outputs=model.get_layer(layername).output) | |
intermediate_output = intermediate_layer_model.predict( | |
input_data, batch_size=batch_size, verbose=1) |