Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor object detection metrics #1046

Merged
merged 9 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion armory/eval/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def get_xy(
else:
y.append(total - failed_benign - (epsilon >= e).sum())

x.append(max_value)
x.add_results(max_value)
if ascending_attack:
y.append(failed_attack)
else:
Expand Down
8 changes: 4 additions & 4 deletions armory/scenarios/poisoning_gtsrb_clbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ def _evaluate(
# Ensure that input sample isn't overwritten by classifier
x.flags.writeable = False
y_pred = classifier.predict(x)
benign_validation_metric.append(y, y_pred)
benign_validation_metric.add_results(y, y_pred)
y_pred_tgt_class = y_pred[y == src_class]
if len(y_pred_tgt_class):
target_class_benign_metric.append(
target_class_benign_metric.add_results(
[src_class] * len(y_pred_tgt_class), y_pred_tgt_class
)
logger.info(
Expand Down Expand Up @@ -293,11 +293,11 @@ def _evaluate(
poisoned_indices,
)
y_pred = classifier.predict(x_test)
poisoned_test_metric.append(y_test, y_pred)
poisoned_test_metric.add_results(y_test, y_pred)

y_pred_targeted = y_pred[y_test == src_class]
if len(y_pred_targeted):
poisoned_targeted_test_metric.append(
poisoned_targeted_test_metric.add_results(
[tgt_class] * len(y_pred_targeted), y_pred_targeted
)
results["poisoned_test_accuracy"] = poisoned_test_metric.mean()
Expand Down
14 changes: 7 additions & 7 deletions armory/scenarios/poisoning_gtsrb_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,10 @@ def _evaluate(
# Ensure that input sample isn't overwritten by classifier
x.flags.writeable = False
y_pred = classifier.predict(x)
benign_validation_metric.append(y, y_pred)
benign_validation_metric.add_results(y, y_pred)
y_pred_tgt_class = y_pred[y == src_class]
if len(y_pred_tgt_class):
target_class_benign_metric.append(
target_class_benign_metric.add_results(
[src_class] * len(y_pred_tgt_class), y_pred_tgt_class
)
logger.info(
Expand Down Expand Up @@ -337,8 +337,8 @@ def _evaluate(
x_poison_test = np.array([xp for xp in x_poison_test], dtype=np.float32)
y_pred = classifier.predict(x_poison_test)
y_true = [src_class] * len(y_pred)
poisoned_targeted_test_metric.append(y_poison_test, y_pred)
poisoned_test_metric.append(y_true, y_pred)
poisoned_targeted_test_metric.add_results(y_poison_test, y_pred)
poisoned_test_metric.add_results(y_true, y_pred)
test_data_clean = load_dataset(
config["dataset"],
epochs=1,
Expand All @@ -351,7 +351,7 @@ def _evaluate(
):
x_clean_test = np.array([xp for xp in x_clean_test], dtype=np.float32)
y_pred = classifier.predict(x_clean_test)
poisoned_test_metric.append(y_clean_test, y_pred)
poisoned_test_metric.add_results(y_clean_test, y_pred)

elif poison_dataset_flag:
logger.info("Testing on poisoned test data")
Expand All @@ -375,12 +375,12 @@ def _evaluate(
poisoned_indices,
)
y_pred = classifier.predict(x_test)
poisoned_test_metric.append(y_test, y_pred)
poisoned_test_metric.add_results(y_test, y_pred)

y_pred_targeted = y_pred[y_test == src_class]
if not len(y_pred_targeted):
continue
poisoned_targeted_test_metric.append(
poisoned_targeted_test_metric.add_results(
[tgt_class] * len(y_pred_targeted), y_pred_targeted
)

Expand Down
4 changes: 1 addition & 3 deletions armory/utils/config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,7 @@
"mean_image_circle_patch_diameter",
"max_image_circle_patch_diameter",
"word_error_rate",
"object_detection_AP_per_class",
"object_detection_class_recall",
"object_detection_class_precision"
"object_detection_AP_per_class"
]
},
"sysconfig": {
Expand Down
Loading