nuclearboy95 / Anomaly-Detection-PatchSVDD-PyTorch

243 stars 56 forks source link

for windows anaconda users, a silly way to solve the problem of not being able to install 'ngtpy' under windows #7

Open opentld opened 3 years ago

opentld commented 3 years ago

Just edit inspection.py, change the 'ngt' method to 'kdt', I don’t know what will happen, but the program is running... :) Is there any problem to do like this? @nuclearboy95

def eval_embeddings_NN_multiK(obj, embs64, embs32, NN=1): emb_tr, emb_te = embs64 maps_64 = measure_emb_NN(emb_te, emb_tr, method='kdt', NN=NN) maps_64 = distribute_scores(maps_64, (256, 256), K=64, S=16) det_64, seg_64 = assess_anomaly_maps(obj, maps_64)

emb_tr, emb_te = embs32

maps_32 = measure_emb_NN(emb_te, emb_tr, method='ngt', NN=NN)

maps_32 = measure_emb_NN(emb_te, emb_tr, method='kdt', NN=NN)
maps_32 = distribute_scores(maps_32, (256, 256), K=32, S=4)
det_32, seg_32 = assess_anomaly_maps(obj, maps_32)

maps_sum = maps_64 + maps_32
det_sum, seg_sum = assess_anomaly_maps(obj, maps_sum)

maps_mult = maps_64 * maps_32
det_mult, seg_mult = assess_anomaly_maps(obj, maps_mult)

return {
    'det_64': det_64,
    'seg_64': seg_64,

    'det_32': det_32,
    'seg_32': seg_32,

    'det_sum': det_sum,
    'seg_sum': seg_sum,

    'det_mult': det_mult,
    'seg_mult': seg_mult,

    'maps_64': maps_64,
    'maps_32': maps_32,
    'maps_sum': maps_sum,
    'maps_mult': maps_mult,
}
nuclearboy95 commented 3 years ago

kdt is an exact NN method, while ngt is an approximate NN method.

The code is designed to use 'ngt' mode for K=32 because the patches are small so a lot of embeddings should be compared.

I recommend you to use 'ngt' mode for K=32 or simply skip K=32 and use only K=64 if 'ngt' is not available.

Sincerely