BETTER-NMA 1.0.5__py3-none-any.whl → 1.0.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- BETTER_NMA/utilss/classes/adversarial_dataset.py +7 -4
- BETTER_NMA/utilss/photos_uitls.py +18 -0
- {BETTER_NMA-1.0.5.dist-info → BETTER_NMA-1.0.6.dist-info}/METADATA +1 -1
- {BETTER_NMA-1.0.5.dist-info → BETTER_NMA-1.0.6.dist-info}/RECORD +6 -6
- {BETTER_NMA-1.0.5.dist-info → BETTER_NMA-1.0.6.dist-info}/WHEEL +0 -0
- {BETTER_NMA-1.0.5.dist-info → BETTER_NMA-1.0.6.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,7 @@
|
|
1
1
|
from sklearn.model_selection import train_test_split
|
2
2
|
import numpy as np
|
3
3
|
from .score_calculator import ScoreCalculator
|
4
|
+
from ..photos_uitls import preprocess_numpy_image
|
4
5
|
|
5
6
|
class AdversarialDataset:
|
6
7
|
def __init__(self, model, clear_images, adversarial_images, Z_full, labels):
|
@@ -16,8 +17,9 @@ class AdversarialDataset:
|
|
16
17
|
try:
|
17
18
|
for image in self.clear_images[:50]:
|
18
19
|
# Add batch dimension for model prediction
|
19
|
-
image_batch = np.expand_dims(image, axis=0)
|
20
|
-
|
20
|
+
# image_batch = np.expand_dims(image, axis=0)
|
21
|
+
preprocessed_img = preprocess_numpy_image(self.model, image)
|
22
|
+
score = self.score_calculator.calculate_adversarial_score(self.model.predict(preprocessed_img, verbose=0))
|
21
23
|
scores.append(score)
|
22
24
|
labels.append(0)
|
23
25
|
except Exception as e:
|
@@ -27,8 +29,9 @@ class AdversarialDataset:
|
|
27
29
|
try:
|
28
30
|
for adv_image in self.adversarial_images[:50]:
|
29
31
|
# Add batch dimension for model prediction
|
30
|
-
adv_image_batch = np.expand_dims(adv_image, axis=0)
|
31
|
-
|
32
|
+
# adv_image_batch = np.expand_dims(adv_image, axis=0)
|
33
|
+
preprocessed_adv_img = preprocess_numpy_image(self.model, adv_image)
|
34
|
+
score = self.score_calculator.calculate_adversarial_score(self.model.predict(preprocessed_adv_img, verbose=0))
|
32
35
|
scores.append(score)
|
33
36
|
labels.append(1)
|
34
37
|
except Exception as e:
|
@@ -69,4 +69,22 @@ def preprocess_image(model, image):
|
|
69
69
|
preprocess_input = get_cached_preprocess_function(model)
|
70
70
|
image_array = preprocess_input(np.array(image))
|
71
71
|
image_preprocessed = np.expand_dims(image_array, axis=0)
|
72
|
+
return image_preprocessed
|
73
|
+
|
74
|
+
def preprocess_numpy_image(model, image):
|
75
|
+
"""
|
76
|
+
Preprocess a NumPy array image for the given model.
|
77
|
+
"""
|
78
|
+
# if isinstance(image, list):
|
79
|
+
# image = np.array(image)
|
80
|
+
if image.ndim == 3:
|
81
|
+
# If the image is 3D, add a batch dimension
|
82
|
+
image = np.expand_dims(image, axis=0)
|
83
|
+
|
84
|
+
# Get the appropriate preprocessing function for the model
|
85
|
+
preprocess_input = get_cached_preprocess_function(model)
|
86
|
+
|
87
|
+
# Apply the preprocessing function
|
88
|
+
image_preprocessed = preprocess_input(image)
|
89
|
+
|
72
90
|
return image_preprocessed
|
@@ -12,12 +12,12 @@ BETTER_NMA/train_adversarial_detector.py,sha256=nMaQ-Pm2vP84qNR1GoKQiVPpmMC3rdor
|
|
12
12
|
BETTER_NMA/white_box_testing.py,sha256=VZ5pImXUOpM6jWMOoIkTWymwPCsev75zQ2SudSJ0frw,3539
|
13
13
|
BETTER_NMA/utilss/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
14
14
|
BETTER_NMA/utilss/models_utils.py,sha256=gBXY2LFH4iR-2GZmHeUnnB5n9t3VdjIc9sugHDrD3AM,671
|
15
|
-
BETTER_NMA/utilss/photos_uitls.py,sha256=
|
15
|
+
BETTER_NMA/utilss/photos_uitls.py,sha256=liGx2exIfGMrJgUngFfCvDLWvoUnISqnwyaDNbUyA1Q,3734
|
16
16
|
BETTER_NMA/utilss/photos_utils.py,sha256=4EjDHbMjrJ8P9y-X4H05P4wez4uKNit60UGnu3sKsys,4412
|
17
17
|
BETTER_NMA/utilss/verbal_explanation.py,sha256=_hrYZUjBUYOfuGr7t5r-DACooR5d60dRtGfUj7FbeZw,549
|
18
18
|
BETTER_NMA/utilss/wordnet_utils.py,sha256=77qcmEQH3Krd1T8dQY-IXVpaEgfwlw406XRk4zYsghw,9482
|
19
19
|
BETTER_NMA/utilss/classes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
20
|
-
BETTER_NMA/utilss/classes/adversarial_dataset.py,sha256=
|
20
|
+
BETTER_NMA/utilss/classes/adversarial_dataset.py,sha256=RGRaaDV9idjMp7GOsUUTVems_1GzswhaiK1Se7y5gFw,2528
|
21
21
|
BETTER_NMA/utilss/classes/adversarial_detector.py,sha256=BE_SxNEwcvuHERBiefefOmk1k6NJSo6juehkAjkEHuQ,2331
|
22
22
|
BETTER_NMA/utilss/classes/dendrogram.py,sha256=vtKBFfwzcz8k01Goc83pZlWC2pO86endTJURlkUWVQI,5141
|
23
23
|
BETTER_NMA/utilss/classes/edges_dataframe.py,sha256=q-RQ6beOeZeIgdEzwi8T5Ag2NBFySv7-ITD5m989nl4,1896
|
@@ -33,7 +33,7 @@ BETTER_NMA/utilss/classes/preprocessing/z_builder.py,sha256=T8ETfL7mMOgEj7oYNsw6
|
|
33
33
|
BETTER_NMA/utilss/enums/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
34
34
|
BETTER_NMA/utilss/enums/explanation_method.py,sha256=Ang-rjvxO4AJ1IH4mwS8sNpSwt9jn3PlqFbPPT-R9I8,150
|
35
35
|
BETTER_NMA/utilss/enums/heap_types.py,sha256=0z1d2qu1ZCbpWRXKD1dTopn3M4G1CxRQW9HWxVxyPIA,88
|
36
|
-
BETTER_NMA-1.0.
|
37
|
-
BETTER_NMA-1.0.
|
38
|
-
BETTER_NMA-1.0.
|
39
|
-
BETTER_NMA-1.0.
|
36
|
+
BETTER_NMA-1.0.6.dist-info/METADATA,sha256=M2D3uM-BAPpo-O7z7ft7HABhe7Oo3kxI8pdn3-lPkgA,5100
|
37
|
+
BETTER_NMA-1.0.6.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
38
|
+
BETTER_NMA-1.0.6.dist-info/top_level.txt,sha256=SVRNqWPvCnynWVyXNAYnf9CSQIvMAvE6iyyiGHodQgY,11
|
39
|
+
BETTER_NMA-1.0.6.dist-info/RECORD,,
|
File without changes
|
File without changes
|