Exemplo n.º 1
0
    topoae_2d_std = '/Users/simons/MT_data/eval_data/MNIST_FINAL/TopoAE/std_minimizer/MNIST_offline-seed1988-DeepAE_MNIST-default-lr1_1000-bs64-nep1000-rlw1-tlw1_256-seed1988-1ae25b75'
    topoae_2d_cont = '/Users/simons/MT_data/eval_data/MNIST_FINAL/TopoAE/cont_minimizer/MNIST_offline-seed579-DeepAE_MNIST-default-lr1_1000-bs128-nep1000-rlw1-tlw1_128-seed579-3c78a835'
    topoae_2d_rec = '/Users/simons/MT_data/eval_data/MNIST_FINAL/TopoAE/rec_minimizer/MNIST_offline-seed838-DeepAE_MNIST-default-lr1_1000-bs256-nep1000-rlw1-tlw1_16-seed838-67de8d97'

    for path_exp in [
            topoae_2d_kl01, topoae_2d_std, topoae_2d_cont, topoae_2d_rec
    ]:
        # get model
        autoencoder = DeepAE_MNIST()

        model = TopologicallyRegularizedAutoencoder(autoencoder)
        state_dict = torch.load(os.path.join(path_exp, 'model_state.pth'),
                                map_location=torch.device('cpu'))

        model.load_state_dict(state_dict)
        model.eval()

        dataset = MNIST_offline()
        data, labels = dataset.sample(train=False)

        z = model.encode(torch.Tensor(data).float())

        plot_2Dscatter(z.detach().numpy(),
                       labels,
                       path_to_save=os.path.join(
                           path_exp,
                           '{}_latent_visualization.pdf'.format('final')),
                       title=None,
                       show=False,
                       palette='custom2')
Exemplo n.º 2
0
from src.datasets.datasets import MNIST_offline
from src.evaluation.config import ConfigEval
from src.models.autoencoder.autoencoders import DeepAE_MNIST_4D
from src.models.vanillaAE.config import ConfigGrid_VanillaAE

mnist_1_deepae4 = [
    ConfigGrid_VanillaAE(
        learning_rate=[1 / 10, 1 / 100, 1 / 1000],
        batch_size=[64, 128, 256, 512],
        n_epochs=[1000],
        weight_decay=[1e-6],
        early_stopping=[32],
        model_class=[DeepAE_MNIST_4D],
        model_kwargs=[dict()],
        dataset=[MNIST_offline()],
        sampling_kwargs=[
            dict(root_path='/cluster/home/schsimo/MT/AEs-VAEs-TDA')
        ],
        eval=[
            ConfigEval(active=True,
                       evaluate_on='test',
                       eval_manifold=False,
                       save_eval_latent=False,
                       save_train_latent=False,
                       online_visualization=False,
                       quant_eval=True,
                       k_min=4,
                       k_max=16,
                       k_step=4)
        ],
import time

import torch
from sklearn.metrics import pairwise_distances
from torch import nn

from src.datasets.datasets import MNIST_offline


data_set = MNIST_offline()

data, labels = data_set.sample(train = True)

data_S = data[:1024,:]

print(data.shape)

start1 = time.time()
distance_matrix1 = pairwise_distances(data, data_S, n_jobs = 2)
end1 = time.time()
print('SKLEARN')
print(end1-start1)
print(distance_matrix1.shape)
print(distance_matrix1[1,0])
print(distance_matrix1[0,1])

data_t = torch.from_numpy(data)
data_ts = torch.from_numpy(data_S)
print(data_t.shape)
start1 = time.time()
distance_matrix3 = torch.cdist(data_t, data_ts)