danieltan07 / dagmm

My attempt at reproducing the paper Deep Autoencoding Gaussian Mixture Model for Unsupervised Anomaly Detection
401 stars 106 forks source link

backward not implemented error #6

Open PiggyGaGa opened 5 years ago

PiggyGaGa commented 5 years ago

when I run the code, it tells me that

File "/usr/local/lib/python3.5/dist-packages/torch/autograd/function.py", line 180, in backward raise NotImplementedError NotImplementedError

HongminWu commented 5 years ago

I encountered the same error.

@PiggyGaGa Did you have the solution for this?

@danieltan07 , please help us to solve it. Thanks in advance...

danieltan07 commented 5 years ago

May I ask what pytorch version are you using? maybe its because of the version differences

HongminWu commented 5 years ago

Thanks for your reply. Currently, my pytorch version is 0.4.1 and Python version is 3.5.6.

On Wed, 20 Feb 2019 at 15:53, Daniel Stanley Tan notifications@github.com wrote:

May I ask what pytorch version are you using? maybe its because of the version differences

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/danieltan07/dagmm/issues/6#issuecomment-465464178, or mute the thread https://github.com/notifications/unsubscribe-auth/ALLZeR3fZfcgMfoquSb8voqW0Y7XcaHuks5vPP7sgaJpZM4bA6Uu .

-- ​ Hongmin Wu, Ph.D. Candidate Biomimetic and Intelligent Robotics Lab. (BIRL) School of Electromechanical Engineering Guangdong University of Technology Guangzhou, Guangdong, P.R.China 510006 WeChat: Homing20 Facebook: Hongmin Wu Tel:86+18819498204 E-mail:hongminwu0120@gmail.com hongminwu0120@gmail.com URL: https://hongminwu.github.io https://hongminwu.github.io/ http://www.juanrojas.net/research/

danieltan07 commented 5 years ago

I think the backward() for potrf in 0.4.1 is still not yet implemented. try replacing this part in model.py line 135 det_cov.append((Cholesky.apply(cov_k.cpu() * (2*np.pi)).diag().prod()).unsqueeze(0)) with det_cov.append(np.linalg.det(cov_k.data.cpu().numpy()* (2*np.pi)))

the code is already there just uncomment it.

HongminWu commented 5 years ago

Thanks for your reply. I tried your idea but it didn't work. However, it works by:

  1. open solver.py file
  2. go to line 167 add command line "total_loss = Variable(total_loss, requires_grad = True)" before the line "total_loss.backward()".

If something wrong there, please let me know.

On Wed, 20 Feb 2019 at 17:27, Daniel Stanley Tan notifications@github.com wrote:

I think the potrf for 0.4.1 is still not yet implemented. try replacing this part in model.py line 135 det_cov.append((Cholesky.apply(cov_k.cpu() (2np.pi)).diag().prod()).unsqueeze(0)) with det_cov.append(np.linalg.det(cov_k.data.cpu().numpy() (2np.pi)))

the code is already there just uncomment it.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/danieltan07/dagmm/issues/6#issuecomment-465494785, or mute the thread https://github.com/notifications/unsubscribe-auth/ALLZeYJVXTNsY5lJXtfcGbjKHLqXcIzgks5vPRTxgaJpZM4bA6Uu .

-- ​ Hongmin Wu, Ph.D. Candidate Biomimetic and Intelligent Robotics Lab. (BIRL) School of Electromechanical Engineering Guangdong University of Technology Guangzhou, Guangdong, P.R.China 510006 WeChat: Homing20 Facebook: Hongmin Wu Tel:86+18819498204 E-mail:hongminwu0120@gmail.com hongminwu0120@gmail.com URL: https://hongminwu.github.io https://hongminwu.github.io/ http://www.juanrojas.net/research/

PiggyGaGa commented 5 years ago

I think the backward() for potrf in 0.4.1 is still not yet implemented. try replacing this part in model.py line 135 det_cov.append((Cholesky.apply(cov_k.cpu() * (2*np.pi)).diag().prod()).unsqueeze(0)) with det_cov.append(np.linalg.det(cov_k.data.cpu().numpy()* (2*np.pi)))

the code is already there just uncomment it.

The problem is on the version of pytorch, the dagmm of this rep uses pytorch 0.4.0, I have tried 0.4.0, 0.4.1 and the latest version, they report the same backward implementation error, I am confused now, I think who is familiar with difference between different versions of torch, then the root of this problem can be found. I am new to torch, still confused

danieltan07 commented 5 years ago

Oh wait sorry, I didn't change the version in README. The original implementation used the numpy to get the determinant. The cholesky version was done by someone else I think using pytorch 1.0.

PiggyGaGa commented 5 years ago

Thanks for your reply. I tried your idea but it didn't work. However, it works by: 1. open solver.py file 2. go to line 167 add command line "total_loss = Variable(total_loss, requires_grad = True)" before the line "total_loss.backward()". If something wrong there, please let me know. On Wed, 20 Feb 2019 at 17:27, Daniel Stanley Tan @.**> wrote: I think the potrf for 0.4.1 is still not yet implemented. try replacing this part in model.py line 135 det_cov.append((Cholesky.apply(cov_k.cpu() (2np.pi)).diag().prod()).unsqueeze(0)) with det_cov.append(np.linalg.det(cov_k.data.cpu().numpy() (2np.pi))) the code is already there just uncomment it. — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#6 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/ALLZeYJVXTNsY5lJXtfcGbjKHLqXcIzgks5vPRTxgaJpZM4bA6Uu . -- ​ Hongmin Wu, Ph.D. Candidate Biomimetic and Intelligent Robotics Lab. (BIRL) School of Electromechanical Engineering Guangdong University of Technology Guangzhou, Guangdong, P.R.China 510006 WeChat: Homing20 Facebook: Hongmin Wu Tel:86+18819498204 E-mail:hongminwu0120@gmail.com hongminwu0120@gmail.com URL: https://hongminwu.github.io https://hongminwu.github.io/ <http://www.juanrojas.net/research/>​*

Thank you for your solution, it success, it seems that the variable total_loss has been changed its requires_grad parameter to false in somewhere, but I don't know exactly where it is, I still interested in the root reason of it.

meihuameii commented 3 years ago

I have a question about the calculation of the matrix determinant: det_cov.append((Cholesky.apply(cov_k.cpu() * (2*np.pi)).diag().prod()).unsqueeze(0))
and det_cov.append(np.linalg.det(cov_k.data.cpu().numpy()* (2*np.pi))) have the same result?