-
Notifications
You must be signed in to change notification settings - Fork 2
/
ModelClassificationEnc.py
79 lines (61 loc) · 1.92 KB
/
ModelClassificationEnc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 12 17:23:05 2022
@author: Simon Bilik
This class is used for the classification of the evaluated model
"""
import logging
import traceback
import numpy as np
from ModelClassificationBase import ModelClassificationBase
class ModelClassificationEnc(ModelClassificationBase):
## Constructor
def __init__(
self,
modelDataPath,
experimentPath,
modelSel,
layerSel,
labelInfo,
imageDim,
modelData,
anomaly_algorithm_selection = ["Robust covariance", "One-Class SVM", "Isolation Forest", "Local Outlier Factor"],
visualize = True
):
# Call the parent
ModelClassificationBase.__init__(
self,
modelDataPath,
experimentPath,
modelSel,
layerSel,
labelInfo,
imageDim,
modelData,
'Enc',
anomaly_algorithm_selection,
visualize
)
# Get data, metrics and classify the data
try:
if self.modelData:
self.procDataFromDict()
else:
self.procDataFromFile()
self.dataClassify()
except:
logging.error('An error occured during classification using ' + self.featExtName + ' feature extraction method...')
traceback.print_exc()
pass
## Compute the classification metrics
def computeMetrics(self, processedData):
# Get the data
encData = processedData.get('Enc')
labels = processedData.get('Lab')
metrics = []
#Flatten the encoded space
for data in encData:
metrics.append(data.flatten())
# Get metrics np array
metrics = self.normalize2DData(np.array(metrics))
return metrics, labels