danieltan07 / dagmm

My attempt at reproducing the paper Deep Autoencoding Gaussian Mixture Model for Unsupervised Anomaly Detection

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can anyone run this codes?

PeterKim1 opened this issue · comments

Hello. Thanks for your great works.

I use Google Colab, and in my Colab notebook, this Error occurs.

`---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
in ()
----> 1 solver = main(hyperparams(defaults))

5 frames
/content/drive/MyDrive/dagmm/main.py in main(config)
23
24 if config.mode == 'train':
---> 25 solver.train()
26 elif config.mode == 'test':
27 solver.test()

/content/drive/MyDrive/dagmm/solver.py in train(self)
95 input_data = self.to_var(input_data)
96
---> 97 total_loss,sample_energy, recon_error, cov_diag = self.dagmm_step(input_data)
98 # Logging
99 loss = {}

/content/drive/MyDrive/dagmm/solver.py in dagmm_step(self, input_data)
162 enc, dec, z, gamma = self.dagmm(input_data)
163
--> 164 total_loss, sample_energy, recon_error, cov_diag = self.dagmm.loss_function(input_data, dec, z, gamma, self.lambda_energy, self.lambda_cov_diag)
165
166 self.reset_grad()

/content/drive/MyDrive/dagmm/model.py in loss_function(self, x, x_hat, z, gamma, lambda_energy, lambda_cov_diag)
166
167 phi, mu, cov = self.compute_gmm_params(z, gamma)
--> 168 sample_energy, cov_diag = self.compute_energy(z, phi, mu, cov)
169
170 loss = recon_error + lambda_energy * sample_energy + lambda_cov_diag * cov_diag

/content/drive/MyDrive/dagmm/model.py in compute_energy(self, z, phi, mu, cov, size_average)
133 cov_inverse.append(torch.inverse(cov_k).unsqueeze(0))
134
--> 135 #det_cov.append(np.linalg.det(cov_k.data.cpu().numpy()* (2np.pi)))
136 det_cov.append((Cholesky.apply(cov_k.cpu() * (2
np.pi)).diag().prod()).unsqueeze(0))
137 cov_diag = cov_diag + torch.sum(1 / cov_k.diag())

/content/drive/MyDrive/dagmm/model.py in forward(ctx, a)
10 class Cholesky(torch.autograd.Function):
11 def forward(ctx, a):
---> 12 l = torch.cholesky(a, False)
13 ctx.save_for_backward(l)
14 return l

AttributeError: module 'torch' has no attribute 'potrf'`

After I search for this error, i knew that torch.potrf removed. it was replaced with torch.cholesky.

pytorch/pytorch#50379

But, after i change torch.potrf to torch.cholesky, same error occurs.

Can anyone run this codes? help me plz.

I tried to change a line inside compute_energy() and the code is running. (I am not running the code in the Colab though)

det_cov.append((Cholesky.apply(cov_k.cpu() * (2np.pi)).diag().prod()).unsqueeze(0)) -->
det_cov.append((torch.cholesky(cov_k * (2
math.pi), False).diag().prod()).unsqueeze(0))

_det_cov.append((torch.cholesky(cov_k * (2_math.pi), False).diag().prod()).unsqueeze(0))

update:
solution 1:
det_cov.append((torch.cholesky(cov_k * (2*math.pi), False).diag().prod()).unsqueeze(0))
solution 2:
det_cov.append((torch.cholesky(cov_k * (2*np.pi), False).diag().prod()).unsqueeze(0))