Gaussian Process Latent Variable Model - Pyro/GPyTorch Integration #2533
Unanswered
MikeSchoenhals
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey guys,
I've been trying to use the code from the examples and create a gaussian process latent variable model using Pyro/GPyTorch integration. However, I'm running into issues - the model isn't learning. The code looks correct to me, but obviously something is wrong. If anyone is able to see what is wrong, it would be much appreciated. I'm using the MNIST dataset to test that the model works (specifically, I'm using the first 2000 data-points to test the model).
`
import matplotlib.pylab as plt
import torch
import os
import numpy as np
from pathlib import Path
import tensorflow as tf
import pyro
from torch.distributions.kl import kl_divergence
import gpytorch
from gpytorch.models.gplvm.latent_variable import *
from gpytorch.models.gplvm.bayesian_gplvm import BayesianGPLVM
from matplotlib import pyplot as plt
from tqdm.notebook import trange
from gpytorch.means import ZeroMean, ConstantMean, LinearMean
from gpytorch.mlls import VariationalELBO
from gpytorch.priors import NormalPrior
from gpytorch.likelihoods import GaussianLikelihood
from gpytorch.variational import VariationalStrategy
from gpytorch.variational import CholeskyVariationalDistribution
from gpytorch.kernels import ScaleKernel, RBFKernel
from gpytorch.distributions import MultivariateNormal
from gpytorch.models import ApproximateGP, GP
from gpytorch.mlls import VariationalELBO, AddedLossTerm
from gpytorch.likelihoods import GaussianLikelihood
from gpytorch.models.deep_gps import DeepGPLayer, DeepGP
from gpytorch.mlls import DeepApproximateMLL
from sklearn.manifold import TSNE
def random_zero_grid(tensor, grid_size=9):
N, H, W = tensor.shape
tensor = torch.tensor(tensor)
mask = torch.ones_like(torch.tensor(tensor),dtype=torch.int64)
(x_train, y_train), (_, _) = tf.keras.datasets.mnist.load_data()
N = 2000
small_x_train = x_train[:N, ...].astype(np.float64) / 256.
small_y_train = y_train[:N]
N_missing = 500
x_missing_train_init = x_train[N:N+N_missing, ...].astype(np.float64) / 256.
x_missing_train, x_missing_mask = random_zero_grid(x_missing_train_init)
y_missing_train = y_train[N:N+N_missing]
observations_ = torch.tensor(small_x_train.reshape(N, -1).transpose())
obs_missing = x_missing_train.reshape(N_missing, -1).transpose(-1,-2)
mask_missing = x_missing_mask.reshape(N_missing, -1).transpose(-2,-1)
class ToyDeepGPHiddenLayer(DeepGPLayer):
def init(self, input_dims, output_dims, num_inducing=30, mean_type='constant'):
if output_dims is None:
inducing_points = torch.randn(num_inducing, input_dims)
batch_shape = torch.Size([])
else:
inducing_points = torch.randn(output_dims, num_inducing, input_dims)
batch_shape = torch.Size([output_dims])
num_hidden_dims = 10
num_output_dims = 28**2
class Latent_DeepGP(DeepGP):
def init(self, hidden_length, name_prefix="DeepGP"):
def plot_results(embed_before, y_train, N):
def main1():
if name == 'main':
`
Beta Was this translation helpful? Give feedback.
All reactions