Skip to content

Commit

Permalink
Merge pull request #2 from jramapuram/hotfix/pytorch0.4
Browse files Browse the repository at this point in the history
layers need int and model needs relative module
  • Loading branch information
jmtomczak committed May 6, 2018
2 parents eea2833 + 32f769b commit bb6ff3e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion models/HVAE_2level.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def calculate_likelihood(self, X, dir, mode='test', S=5000, MB=500):
x_single = X[j].unsqueeze(0)

a = []
for r in range(0, R):
for r in range(0, int(R)):
# Repeat it for all training points
x = x_single.expand(S, x_single.size(1))

Expand Down
2 changes: 1 addition & 1 deletion models/PixelHVAE_2level.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def calculate_likelihood(self, X, dir, mode='test', S=5000, MB=500):
x_single = X[j].unsqueeze(0)

a = []
for r in range(0, R):
for r in range(0, int(R)):
# Repeat it for all training points
x = x_single.expand(S, x_single.size(1)).contiguous()

Expand Down
4 changes: 2 additions & 2 deletions models/VAE.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from utils.visual_evaluation import plot_histogram
from utils.nn import he_init, GatedDense, NonLinear

from Model import Model
from models.Model import Model
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

#=======================================================================================================================
Expand Down Expand Up @@ -108,7 +108,7 @@ def calculate_likelihood(self, X, dir, mode='test', S=5000, MB=100):
x_single = X[j].unsqueeze(0)

a = []
for r in range(0, R):
for r in range(0, int(R)):
# Repeat it for all training points
x = x_single.expand(S, x_single.size(1))

Expand Down
2 changes: 1 addition & 1 deletion models/convHVAE_2level.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def calculate_likelihood(self, X, dir, mode='test', S=5000, MB=500):
x_single = X[j].unsqueeze(0)

a = []
for r in range(0, R):
for r in range(0, int(R)):
# Repeat it for all training points
x = x_single.expand(S, x_single.size(1)).contiguous()

Expand Down
21 changes: 17 additions & 4 deletions utils/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,22 @@ def evaluate_vae(args, model, train_loader, data_loader, epoch, dir, mode):

if mode == 'test':
# load all data
test_data = Variable(data_loader.dataset.data_tensor)
test_target = Variable(data_loader.dataset.target_tensor)
full_data = Variable(train_loader.dataset.data_tensor)
# grab the test data by iterating over the loader
# there is no standardized tensor_dataset member across pytorch datasets
test_data, test_target = [], []
for data, lbls in data_loader:
test_data.append(data)
test_target.append(lbls)

test_data, test_target = [torch.cat(test_data, 0), torch.cat(test_target, 0).squeeze()]

# grab the train data by iterating over the loader
# there is no standardized tensor_dataset member across pytorch datasets
full_data = []
for data, _ in train_loader:
full_data.append(data)

full_data = torch.cat(full_data, 0)

if args.cuda:
test_data, test_target, full_data = test_data.cuda(), test_target.cuda(), full_data.cuda()
Expand Down Expand Up @@ -110,4 +123,4 @@ def evaluate_vae(args, model, train_loader, data_loader, epoch, dir, mode):
if mode == 'test':
return evaluate_loss, evaluate_re, evaluate_kl, log_likelihood_test, log_likelihood_train, elbo_test, elbo_train
else:
return evaluate_loss, evaluate_re, evaluate_kl
return evaluate_loss, evaluate_re, evaluate_kl
4 changes: 2 additions & 2 deletions utils/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, input_size, output_size, bias=True, activation=None):
super(NonLinear, self).__init__()

self.activation = activation
self.linear = nn.Linear(input_size, output_size, bias=bias)
self.linear = nn.Linear(int(input_size), int(output_size), bias=bias)

def forward(self, x):
h = self.linear(x)
Expand Down Expand Up @@ -301,4 +301,4 @@ def forward(self, x):
h2 = self.bn2(h1)
h2 = self.act(h2)
h2 = self.h2(h2)
return x + h2
return x + h2

0 comments on commit bb6ff3e

Please sign in to comment.