Несоответствие оси с графиками визуализации t-SNE - PullRequest
0 голосов
/ 08 марта 2020

Я просто возился с некоторыми встраиваниями, InceptionV3 и t-SNE. Я довольно новичок в этой области исследований, поэтому заранее прошу прощения, если это можно было легко исправить или я сделал что-то не так.

По сути, я сделал снимок двух ошибок на склоне, скормил их в модель, где был удален последний слой, и нанесите на карту внедрение.

Вот два изображения: slope_1 slope_2

И эти графики из двух разных итераций. Будучи новичком, я не знаю, как создавать участки с дополнительной информацией о них, так что сейчас это просто простой точечный график

plot1 plot2

Я быстро заметил, что на некоторых итерациях графики расходятся от 0, но иногда это разделение происходит либо по оси X, либо по оси Y, в зависимости от того, какой модуль t-SNE, из-за отсутствия лучшего термин "чувствует себя как." Они просто переворачиваются.

Наконец, на всякий случай, вот мой код

import tensorflow as tf
import tensorflow.keras as keras
import tensorflow.keras.backend as K
import numpy as np
from tensorflow.keras.layers import Dense, Input, Layer
from tensorflow.keras.models import Model
from tensorflow.keras.applications.inception_v3 import InceptionV3
from tensorflow.keras.preprocessing import image

from tensorflow.keras.applications.inception_v3 import preprocess_input, decode_predictions

# Numerical computation requirements
import numpy as np 
from numpy import linalg, load, expand_dims, asarray, savez_compressed, append
from numpy.linalg import norm
import pandas as pd

# Plotting requirements
import matplotlib
from matplotlib import pyplot as plt
import matplotlib.patheffects as PathEffects
from matplotlib.animation import FuncAnimation as ani
import seaborn as sb

# Clustering requirements
import sklearn
from sklearn.cluster import KMeans
from sklearn.manifold import TSNE
from sklearn.preprocessing import scale


# model = InceptionV3()
model = InceptionV3(weights='imagenet')

imgs = [
"slope_failure_1.jpg",
"slope_failure_1.jpg",
"slope_failure_1.jpg",
"slope_failure_1.jpg",
"slope_failure_1.jpg",
"slope_failure_1.jpg",
"slope_failure_1.jpg",
"slope_failure_1.jpg",
"slope_failure_1.jpg",
"slope_failure_1.jpg",
"slope_failure_1.jpg",
"slope_failure_1.jpg",
"slope_failure_1.jpg",
"slope_failure_1.jpg",
"slope_failure_1.jpg",
"slope_failure_1.jpg",
"slope_failure_1.jpg",
"slope_failure_1.jpg",
"slope_failure_1.jpg",
"slope_failure_1.jpg",
"slope_failure_1.jpg",

"slope_failure_2.jpg",
"slope_failure_2.jpg",
"slope_failure_2.jpg",
"slope_failure_2.jpg",
"slope_failure_2.jpg",
"slope_failure_2.jpg",
"slope_failure_2.jpg",
"slope_failure_2.jpg",
"slope_failure_2.jpg",
"slope_failure_2.jpg",
"slope_failure_2.jpg",
"slope_failure_2.jpg",
"slope_failure_2.jpg",
"slope_failure_2.jpg",
"slope_failure_2.jpg",
"slope_failure_2.jpg",
"slope_failure_2.jpg",
"slope_failure_2.jpg",
"slope_failure_2.jpg",
"slope_failure_2.jpg",
"slope_failure_2.jpg",

]

targets = []
#need to prepare image for model

for images in imgs:

    img = image.load_img(images, target_size=(299, 299))
    x = image.img_to_array(img)
    x = np.expand_dims(x,axis=0)
    x = preprocess_input(x)
    targets.append(x)

output = model.layers[-2].output
modele = Model(inputs = model.input, outputs = output)

pred = []

for a in targets:
    y = modele.predict(a)
    pred.append(y)


# Initialize Seaborn plots
#sb.set_style('darkgrid')
#sb.set_palette('muted')
#sb.set_context('notebook', font_scale=1.5, rc={'lines.linewidth': 10})

# Matplotlib animation requirements?
plt.style.use('fivethirtyeight')

def scatter(ip):
    palette = np.array(sb.color_palette('hls', 26))

    plot = plt.figure(figsize=(3,6))
    ax = plt.subplot(aspect='equal')
    # sc = ax.scatter(x[:,0],x[:,1], lw =0, s=120, c=palette[colors.astype(np.int)])
    sc = ax.scatter(ip[:,0],ip[:,1], lw =0, s=120)
    labels = []

    return plot , ax, sc, labels

#pred = expand_dims(pred, axis=0)
pred = asarray(pred)

pred = pred[:,0,:]
p = TSNE(random_state = 12345678).fit_transform(pred)

scatter(p)
plt.show()

Может кто-нибудь объяснить мне это?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...