kkirchheim / pytorch-ood

👽 Out-of-Distribution Detection with PyTorch
https://pytorch-ood.readthedocs.io/
Apache License 2.0
247 stars 24 forks source link

DeepSVDD Loss for classification #6

Closed IsaacSheidlower closed 1 year ago

IsaacSheidlower commented 1 year ago

Hello,

For the implimentation of DeepSVDD, I am wondering is there a way to access the radius term referred to in the paper? Specfically I am interested in using R to follow the paper's suggestion "For soft-boundary Deep SVDD, we can adjust this score by subtracting the final radius R∗ of the trained model such that anomalies (points with representations outside the sphere) have positive scores, whereas inliers have negative scores."

Please let me know. Thank you very much!

IsaacSheidlower commented 1 year ago

Nevermind! I learned that the radius can be derived given the center from the implimentation and the dataset. Thank you very much.

kkirchheim commented 1 year ago

Hi,

the variant implemented here is the soft margin version, where the radius is 0. Implementing a version with radius should not be difficult. If you still require this feature, we could include it in a future release. Just let us know. In any case, we should mention this in the documentation.

IsaacSheidlower commented 1 year ago

Hello,

Thank you for the response. I think that would be helpful. Or if you could point me in the direction of how to do binary classification with this loss that would be great. I think in the soft case, the paper talks about points "outside this halfspace, i.e. hw, φk(x)iFk < ρ, are deemed to be anamoulous." but again I am unsure how to get ρ. Thanks again.

kkirchheim commented 1 year ago

Hi,

I added an implementation with a radius in f6a8acb69535f16741e9cfd3ce00b5b18e954c66. However, I could not get good results for the MNIST benchmark when using a radius > 0.01.

If, by ρ, you mean the radius R of the hypersphere, I think that right now you either have to set it a priori or determine a good value on a validation set after training. Once you have a value R, you can subtract R from the distance() of your samples and check for < 0.

The paper also mentions the possibility to optimize the radius together with the other parameters, however, this would require further modification of the training procedure.