Skip to content

Commit

Permalink
fix: Fix classification crash when only images without gt are used
Browse files Browse the repository at this point in the history
* fix: Fix classificatio crash when only images without gt are used for testing

* build: Bump version 1.2.6 -> 1.2.7

* docs: Update changelog

Approved By: @rcmalli
  • Loading branch information
lorenzomammana authored Oct 4, 2023
1 parent 786cca5 commit d473e25
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
# Changelog
All notable changes to this project will be documented in this file.

### [1.2.7]

#### Fixed

- Fix test classification task crash when only images with no labels are used.

### [1.2.6]

#### Added
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "quadra"
version = "1.2.6"
version = "1.2.7"
description = "Deep Learning experiment orchestration library"
authors = [
{ name = "Alessandro Polidori", email = "[email protected]" },
Expand Down Expand Up @@ -118,7 +118,7 @@ repository = "https://github.com/orobix/quadra"

# Adapted from https://realpython.com/pypi-publish-python-package/#version-your-package
[tool.bumpver]
current_version = "1.2.6"
current_version = "1.2.7"
version_pattern = "MAJOR.MINOR.PATCH"
commit_message = "build: Bump version {old_version} -> {new_version}"
commit = true
Expand Down
2 changes: 1 addition & 1 deletion quadra/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.2.6"
__version__ = "1.2.7"


def get_version():
Expand Down
39 changes: 20 additions & 19 deletions quadra/utils/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,20 +400,20 @@ def get_split(
def save_classification_result(
results: pd.DataFrame,
output_folder: str,
confmat: pd.DataFrame,
accuracy: float,
test_dataloader: DataLoader,
config: DictConfig,
output: DictConfig,
accuracy: Optional[float] = None,
confmat: Optional[pd.DataFrame] = None,
grayscale_cams: Optional[np.ndarray] = None,
):
"""Save csv results, confusion matrix and example images.
Args:
results: Dataframe containing the results
output_folder: Path to the output folder
confmat: Confusion matrix in a pandas dataframe
accuracy: Accuracy of the model
confmat: Confusion matrix in a pandas dataframe, may be None if all test labels are unknown
accuracy: Accuracy of the model, is None if all test labels are unknown
test_dataloader: Dataloader used for testing
config: Configuration file
output: Output configuration
Expand All @@ -429,20 +429,21 @@ def save_classification_result(
log.info("Plotting original and gradcam examples")
save_gradcams = True

# Save confusion matrix
disp = ConfusionMatrixDisplay(
confusion_matrix=np.array(confmat),
display_labels=[x.replace("pred:", "") for x in confmat.columns.to_list()],
)
disp.plot(include_values=True, cmap=plt.cm.Greens, ax=None, colorbar=False, xticks_rotation=90)
plt.title(f"Confusion Matrix (Accuracy: {(accuracy * 100):.2f}%)")
plt.savefig(
os.path.join(output_folder, "test_confusion_matrix.png"),
bbox_inches="tight",
pad_inches=0,
dpi=300,
)
plt.close()
if confmat is not None and accuracy is not None:
# Save confusion matrix
disp = ConfusionMatrixDisplay(
confusion_matrix=np.array(confmat),
display_labels=[x.replace("pred:", "") for x in confmat.columns.to_list()],
)
disp.plot(include_values=True, cmap=plt.cm.Greens, ax=None, colorbar=False, xticks_rotation=90)
plt.title(f"Confusion Matrix (Accuracy: {(accuracy * 100):.2f}%)")
plt.savefig(
os.path.join(output_folder, "test_confusion_matrix.png"),
bbox_inches="tight",
pad_inches=0,
dpi=300,
)
plt.close()

if output is not None and output.example:
log.info("Saving discordant/concordant examples in test folder")
Expand All @@ -462,7 +463,7 @@ def save_classification_result(
os.makedirs(gradcam_folder)

for v in np.unique([results["real_label"], results["pred_label"]]):
if np.isnan(v):
if np.isnan(v) or v == -1:
continue

k = idx_to_class[v]
Expand Down

0 comments on commit d473e25

Please sign in to comment.