Hi,
I have just recieved this error when trying to feed a sample into a CVAE. I’m not sure what it means.
The section which generates the error is below, with test_out=model.sample(test_input) seems to be line of interest.
class model(nn.Module):
def __init__(self,lat_dim=50 ):
super(model, self).__init__()
self.Encoder=Encoder(lat_dim)
self.Decoder=Decoder(lat_dim)
self.cuda()
self.lat_dim=lat_dim
def sample(self, epsilon=None):
if epsilon is None:
epsilon = torch.randn(100, self.lat_dim)
print("epsilon=", epsilon)
return self.decode(epsilon, apply_sigmoid=True)
def gen_example(model,epoch,test_input):
x_axis=np.arange(1,1024,1)
test_out=model.cuda()
test_out=model.sample(test_input) ## this is the bit it is failing on.
fig=plt.figure(figsize(5,5))
for i in range(test_out.shape[0]):
plt.subplot(5, 5, i+1)
plt.plot(test_out[i, :, 0], x_axis)
plt.show()
The testing loop is initiated here:
if epoch % 1 == 0:
for i , (test_x, target) in enumerate( test_loader2):
test_x=test_x.unsqueeze(1)
test_x=test_x.cuda()
loss,out_t,logqz_x,logpz,logpx_z,z2=loss_fn(model,test_x)
loss=torch.mean(loss)
elbo=-loss
print("epoch=",epoch,"elbo=",elbo)
gen_example(model,epoch,random_vector_for_gen)
regards,
Chaslie