lukasruff / deep-svdd-pytorch Goto Github PK
View Code? Open in Web Editor NEWA PyTorch implementation of the Deep SVDD anomaly detection method
License: MIT License
A PyTorch implementation of the Deep SVDD anomaly detection method
License: MIT License
Is it possible to set multiple classes as normal classes
And how to do that??
Hi,
Thanks for sharing your source code! I clone this repository and run the experiment of cifar10 with digit 6 as the known class samples by the following command:
python main.py \
cifar10 \
cifar10_LeNet \
../log/cifar10_test \
../data \
--objective one-class \
--lr 0.0001 \
--n_epochs 150 \
--lr_milestone 50 \
--batch_size 200 \
--weight_decay 0.5e-6 \
--pretrain True \
--ae_lr 0.0001 \
--ae_n_epochs 350 \
--ae_lr_milestone 250 \
--ae_batch_size 200 \
--ae_weight_decay 0.5e-6 \
--normal_class 7
However, the result is:
INFO:root:Training time: 183.387
INFO:root:Finished training.
INFO:root:Starting testing...
INFO:root:Testing time: 1.911
INFO:root:Test set AUC: 60.59%
INFO:root:Finished testing.
Could you please help me with this?
Traceback (most recent call last):
File "d:\gitdownload\TS\Anomaly_detection\Deep-SVDD-PyTorch\src\main.py", line 56, in
def main(dataset_name, net_name, xp_path, data_path, load_config, load_model, objective, nu, device, seed,
File "C:\Users\PC.conda\envs\TS\lib\site-packages\click\decorators.py", line 373, in decorator
_param_memo(f, cls(param_decls, **attrs))
File "C:\Users\PC.conda\envs\TS\lib\site-packages\click\core.py", line 2536, in init
super().init(param_decls, type=type, multiple=multiple, **attrs)
File "C:\Users\PC.conda\envs\TS\lib\site-packages\click\core.py", line 2151, in init
raise ValueError(
ValueError: 'default' must be a list when 'multiple' is true.
will you please help on this?
Hi,
I would like to extend the framework to work with 3D (medical) images (e.g. size 128x128x128). Since choice of the autoencoder's architecture is important, I was wondering if you would be able to give some brief insight or intuition on how to approach it.
Thank you!
Hi @lukasruff ,
Could you please explain how can I map the predicted scores into predicted labels to compute precision, recall and f1 score. Line 147 from src/optim/deepSVDD_trainer.py
_, labels, scores = zip(*idx_label_score)
For soft-boundary, I found in the paper that +ve values are considered as outliers while negative values (< 0) are treated are normal (inliers). Does this apply to the one-class
objective as well?
Thanks,
We don't need to update value of c (center of volume) during the training?
Deep-SVDD-PyTorch/src/optim/deepSVDD_trainer.py
Lines 179 to 181 in 1919546
Hi, I think this line 181 is wrong. We can modify this line to
np.quantile(np.sqrt(dist.clone().data.cpu().numpy()), 1-nu).
Because dist is (feat - center)**2 and we are comparing dist to R^2 in
.In your code, there is a constant variable, min_max
in mnsit.py
:
# Pre-computed min and max values (after applying GCN) from train data per class
min_max = [(-0.8826567065619495, 9.001545489292527),
(-0.6661464580883915, 20.108062262467364),
(-0.7820454743183202, 11.665100841080346),
(-0.7645772083211267, 12.895051191467457),
(-0.7253923114302238, 12.683235701611533),
(-0.7698501867861425, 13.103278415430502),
(-0.778418217980696, 10.457837397569108),
(-0.7129780970522351, 12.057777597673047),
(-0.8280402650205075, 10.581538445782988),
(-0.7369959242164307, 10.697039838804978)]
I've tried to get this number by myself using a global_contrast_normalization
function, but I couldn't get it. Here is what I've tried:
train_set = dsets.MNIST(root='data/', train=True, download=True)
test_set = dsets.MNIST(root='data/', train=False, download=True)
train_data = train_set.train_data.float()
train_label = train_set.train_labels.numpy()
# 1. Normalize whole data
data = train_data
label = train_label
digit = 0
given_index = np.where(label==digit)[0]
data = global_contrast_normalization(data, scale='l1')
print(data[given_index].max())
# 2. Normalize label by label
data = train_data
label = train_label
digit = 0
given_index = np.where(label==digit)[0]
data = global_contrast_normalization(data[given_index], scale='l1')
print(data.max())
But the values are different with the min_max
values.
Did I miss something? Could you let me know how I can get that numbers?
As you when we set seed to any number except -1, the result must not change by rerunning. however, I set the seed to 10 and use preparing. So the results of both pretraining and training change widely. It is worth mentioning that if you set pretraining False, the network is trained without any pre-trained weights and the result of many times training is the same for the specific seed value. (of course except -1)
Does anybody know why seed (use for reproducibility) does not work for autoencoder?
I'm new in Pytorch, but I've found out in the autoencoder part, you use conv2d in decoder, I wonder why?
Also, if I increase epoch in training autoencoder, the AUC of ae will be larger than SVDD, does this mean ae is better than SVDD?
Hi, I have a question regarding the L2 normalization. Since we want to map the anomalies fall outside the hypersphere, we might perform L2 normalization before calculating the embedding distance. But I didn't find the L2-norm in the code. Did I misunderstand something?
Thank you in advance!
In GCN preporcessing, if a tensor x has the same feature values (e.g., a pixel with RGB = [255, 255, 255]), after mean removal, the L1-norm scale would be equal to 0, which results in 0 / 0. How would you avoid this? Thanks.
It requires "log.txt", "result.json", "model.tar" such files and so on.
But how could I get these files to fill the "/log/" folder?
There is no related content in "Readme.md". So now I'm really confused.
Thanks.
i am working in google colab after finishing all the requirements is shows that error for both mnist and cifar kindly help it
Hi, I am mystified by this (Average AUCs in % with StdDevs (over 10 seeds) ).
Do you mean to get the average results over 10 seeds.
If then, what should be the range of seeds? (1 - 10 ? or 10 -20 ?). The results varied widely, because of different seed settings.
Can you help me with this question? Thank you.
First, How can I get min-max values for a new dataset? I cannot find the code.
Second, there is a Bug exists in this code that no matter how I change the normal_class number, It always chooses 0 class as normal_class.
If you load pretrained model and weights for Autoencoder and pretrain = True, in deepSVDD.pretrain, it will build a new autoencoder without weights.
I think there's a problem with precomputing min-max values for separate classes. The problem is that this technique will not be suitable for a new and "unknown" sample.
from datasets/cifar10.py
# Pre-computed min and max values (after applying GCN) from train data per class
min_max = [(-28.94083453598571, 13.802961825439636),
(-6.681770233365245, 9.158067708230273),
(-34.924463588638204, 14.419298165027628),
(-10.599172931391799, 11.093187820377565),
(-11.945022995801637, 10.628045447867583),
(-9.691969487694928, 8.948326776180823),
(-9.174940012342555, 13.847014686472365),
(-6.876682005899029, 12.282371383343161),
(-15.603507135507172, 15.2464923804279),
(-6.132882973622672, 8.046098172351265)]
Or am I missing something?
Hello, Thanks for your source codes.
Could I ask Why do not update batchnorm mean and var during training?
affine=False means do not update batch normalization parameters.
Thanks
According to PyTorch docs, the Normalize transform expects the mean and std for every channel.
CLASS torchvision.transforms.Normalize(mean, std, inplace=False)
But currently, this implementation of Deep SVDD passes the "min" value in place of "mean" and "max - min" value in place of std. And that too, for only one channel even in case of CIFAR-10.
from datasets/cifar10.py line 35
> transforms.Normalize([min_max[normal_class][0]] * 3,
[min_max[normal_class][1] - min_max[normal_class][0]] * 3)])
Is this intentional or a real issue?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.