def visualize2D(model, layerID, inputData, labels, withTime = False):
print("\n Generating output distribution for layer {}".format(layerID))
vLayer = K.function([model.layers[0].input], [model.layers[layerID].output])
result = vLayer([inputData])
values = []
for instance in result:
for line in instance:
array = []
for val in line:
if withTime:
for deepVal in val:
array.append(deepVal)
else:
array.append(val)
values.append(array)
npvalues = np.array(values)
model = TSNE(n_components = 2, random_state = 0)
# model = PCA(n_components = 2)
scatterValues = model.fit_transform(npvalues)
labels2D = np.zeros((len(labels), 1))
for i in range(len(labels)):
labels2D[i][0] = labels[i]
scatterValues = np.hstack((scatterValues, labels2D))
dFrame = pd.DataFrame(scatterValues, columns = ('a', 'b', 'c'))
plot = dFrame.plot.scatter(x = 'a', y = 'b', c = 'c', cmap = 'plasma')
fig = plot.get_figure()
fig.savefig('{}/{}'.format(cc.cfg['plots']['dir'],SCATTER_NAME))
print(" ...done")
评论列表
文章目录