lukasruff / Deep-SVDD-PyTorch

A PyTorch implementation of the Deep SVDD anomaly detection method
MIT License
698 stars 197 forks source link

Two Questions #6

Closed Captainsean007 closed 5 years ago

Captainsean007 commented 5 years ago

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.

lukasruff commented 5 years ago
  1. You get the min-max values as the minimum and maximum feature (i.e. Pixel) values over all training set samples after having applied GCN (Global Contrast Normalization) to them. You find the code for GCN in the global_contrast_normalization-function in src/datasets/preprocessing.py. Note that we applied GCN with the L1-norm. Also note that the training sets in the one-class classification setting always only consist of the training samples from the respective normal class. Let me know if you cannot reproduce our precomputed values.

  2. This should not be the case. You can change the normal class with the --normal_class option in the main.py script, e.g. --normal_class 3. If no class is specified, the default is normal_class = 0. Could you provide code for reproducing the error?

Captainsean007 commented 5 years ago

Hi lukasruff,

Thinks for your answers, I have achived this code on my own application. This is a good idea!
matteoguarrera commented 3 years ago
  1. You get the min-max values as the minimum and maximum feature (i.e. Pixel) values over all training set samples after having applied GCN (Global Contrast Normalization) to them. You find the code for GCN in the global_contrast_normalization-function in src/datasets/preprocessing.py. Note that we applied GCN with the L1-norm. Also note that the training sets in the one-class classification setting always only consist of the training samples from the respective normal class. Let me know if you cannot reproduce our precomputed values.

I'm not able to reproduce your min-max value, can you provide the code for doing it?

matteoguarrera commented 3 years ago
train_set_full = MyMNIST(root=root, train=True, download=True,
                        transform=None, target_transform=None)

MIN = []
MAX = []
for normal_classes in range(10):
    train_idx_normal = get_target_label_idx(train_set_full.train_labels.clone().data.cpu().numpy(), normal_classes)
    train_set = Subset(train_set_full, train_idx_normal)

    _min_ = []
    _max_ = []
    for idx in train_set.indices:
        gcm = global_contrast_normalization(train_set.dataset.data[idx].float(), 'l1')
        _min_.append(gcm.min())
        _max_.append(gcm.max())
    MIN.append(np.min(_min_))
    MAX.append(np.max(_max_))
print(list(zip(MIN, MAX)))
btdat2506 commented 11 months ago

Hi lukasruff,

Thinks for your answers, I have achived this code on my own application. This is a good idea!

Can you share me your code that you achieved? @Captainsean007