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

Feat/example yolov5 #50

Merged
merged 42 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
c0c3526
example for yolov5 usage
kamilrzechowski Jan 17, 2023
01f8511
Revert "example for yolov5 usage"
kamilrzechowski Jan 17, 2023
d28d73b
example yolov5 usage with Noisetunnel
kamilrzechowski Jan 17, 2023
ab987ba
poetry updated
kamilrzechowski Jan 18, 2023
ebe8a7b
resolved conflicts with main
kamilrzechowski Jan 18, 2023
14c7975
better functions docstrings
kamilrzechowski Jan 18, 2023
810519e
removinf conf and iou from global variables
kamilrzechowski Jan 18, 2023
7149b82
yolo example in jupiter notebook
kamilrzechowski Jan 19, 2023
c184e49
poetry.lock update
kamilrzechowski Jan 19, 2023
52776b3
better xai_non_max_suppression description
kamilrzechowski Jan 19, 2023
81d69f0
Merge branch 'main' into feat/example_yolov5
kamilrzechowski Jan 24, 2023
f39927d
Update example/yolov5_exmaple/yolo_xai.ipynb
kamilrzechowski Jan 25, 2023
9f3a86c
Update example/yolov5_exmaple/yolo_xai.ipynb
kamilrzechowski Jan 25, 2023
3b88158
Update example/yolov5_exmaple/yolo_xai.ipynb
kamilrzechowski Jan 25, 2023
c840acc
Update example/yolov5_exmaple/yolo_xai.ipynb
kamilrzechowski Jan 25, 2023
379763e
Update example/yolov5_exmaple/yolo_xai.ipynb
kamilrzechowski Jan 25, 2023
77f5e32
more docstrings
kamilrzechowski Jan 25, 2023
5e04b94
better doscstrings
kamilrzechowski Jan 25, 2023
2a7ce72
typing and unnecessery arguments added/removed
kamilrzechowski Jan 25, 2023
224206d
nbstripout added
kamilrzechowski Jan 25, 2023
1408b83
ipynb with gradcam example for yolo_v5
kamilrzechowski Jan 25, 2023
ffc5e38
range for class_confidence extracted to the named variable
kamilrzechowski Jan 25, 2023
d4f798c
credits given for authors of reused function in yolo porcessing
kamilrzechowski Jan 25, 2023
9fdb819
conflicts with main resolved
kamilrzechowski Jan 25, 2023
09774a2
Update example/yolov5_exmaple/yolo_utils.py
kamilrzechowski Jan 26, 2023
fb55ea0
Update example/yolov5_exmaple/yolo_utils.py
kamilrzechowski Jan 26, 2023
b9565c8
Update example/yolov5_exmaple/yolo_utils.py
kamilrzechowski Jan 26, 2023
21b9d21
Update example/yolov5_exmaple/yolo_xai.py
kamilrzechowski Jan 26, 2023
0a7f2c9
Update example/yolov5_exmaple/yolo_xai.ipynb
kamilrzechowski Jan 26, 2023
6d21b87
Update example/yolov5_exmaple/yolo_xai.ipynb
kamilrzechowski Jan 26, 2023
7fbd40d
Update example/yolov5_exmaple/yolo_xai.ipynb
kamilrzechowski Jan 26, 2023
9ca4bfb
Update example/yolov5_exmaple/yolo_xai.ipynb
kamilrzechowski Jan 26, 2023
a2f77e4
Update example/yolov5_exmaple/yolo_xai.ipynb
kamilrzechowski Jan 26, 2023
7c78982
Update example/yolov5_exmaple/yolo_xai.ipynb
kamilrzechowski Jan 26, 2023
65b43bf
Update example/yolov5_exmaple/yolo_xai.ipynb
kamilrzechowski Jan 26, 2023
d7bbe87
Update example/yolov5_exmaple/yolo_xai.ipynb
kamilrzechowski Jan 26, 2023
466201b
Update example/yolov5_exmaple/yolo_xai.ipynb
kamilrzechowski Jan 26, 2023
31aec8e
commented unused lines of code removed. pyproject.toml torch dependen…
kamilrzechowski Jan 26, 2023
cdb93ee
ipynb same as yolo_xai.py
kamilrzechowski Jan 26, 2023
57d46ae
mypy error with torch.device fixed. Thank you Adam W.
kamilrzechowski Jan 26, 2023
9759774
removed mypy ignore from experiment_update.py
kamilrzechowski Jan 26, 2023
f1428cd
constant variables extracted outside of the NMS algorithm
kamilrzechowski Jan 26, 2023
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
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.ipynb filter=nbstripout
*.zpln filter=nbstripout
*.ipynb diff=ipynb
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,7 @@ cython_debug/

# VS Code
.vscode/

# pytorch checkpoints
*.pt
*.pth
2 changes: 1 addition & 1 deletion autoxai/array_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def resize_attributes(
single_channel_attributes: np.ndarray = np.array(
cv2.resize(
attributes,
(dest_height, dest_width),
(dest_width, dest_height),
)
)

Expand Down
6 changes: 3 additions & 3 deletions autoxai/callbacks/wandb_callback.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""Callback for Weights and Biases."""
from collections import defaultdict
from typing import Dict, Generator, List, Optional, Tuple
from typing import Dict, Generator, List, Optional, Tuple, cast

import matplotlib
import numpy as np
import pytorch_lightning as pl
import torch
import wandb
from pytorch_lightning.loggers import WandbLogger
from torch.utils.data import DataLoader

import wandb
from autoxai.array_utils import convert_float_to_uint8
from autoxai.context_manager import AutoXaiExplainer, ExplainerWithParams
from autoxai.explainer.base_explainer import CVExplainer
Expand Down Expand Up @@ -106,7 +106,7 @@ def explain( # pylint: disable = (too-many-arguments)
explainers=self.explainers,
target=int(target_label.item()),
) as xai_model:
_, attributes = xai_model(item.to(model.device))
_, attributes = xai_model(item.to(cast(torch.device, model.device)))

for explainer in self.explainers:
explainer_name: str = explainer.explainer_name.name
Expand Down
5 changes: 3 additions & 2 deletions autoxai/cli/experiment_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import pandas as pd
import pytorch_lightning as pl
import torch
import wandb
from omegaconf import DictConfig
from torchvision.io import ImageReadMode, read_image

import wandb
from autoxai.cli.config_model import ConfigDataModel, MethodDataModel
from autoxai.context_manager import AutoXaiExplainer, Explainers, ExplainerWithParams

Expand Down Expand Up @@ -210,7 +210,8 @@ def main(cfg: DictConfig) -> None: # pylint: disable = (too-many-locals)
target=label,
) as xai_model:
input_data = input_data.float()
_, attributes_dict = xai_model(input_data.to(model.device))
# type: ignore
_, attributes_dict = xai_model(input_data.to(model.device)) # type: ignore # type: ignore
explainer_name: str = (
explainer_config.explainer_with_params.explainer_name.name
)
Expand Down
8 changes: 4 additions & 4 deletions autoxai/explainer/noise_tunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def calculate_features(
pred_label_idx: TargetType = None,
nt_type: str = "smoothgrad",
nt_samples: int = 5,
nt_samples_batch_size: int = None,
nt_samples_batch_size: Optional[int] = None,
stdevs: Union[float, Tuple[float, ...]] = 1.0,
draw_baseline_from_distrib: bool = False,
**kwargs,
Expand Down Expand Up @@ -118,13 +118,13 @@ def calculate_features(
noise_tunnel = self.create_explainer(model=model, layer=layer)

attributions = noise_tunnel.attribute(
input_data,
nt_samples=nt_samples,
inputs=input_data,
nt_type=nt_type,
target=pred_label_idx,
nt_samples=nt_samples,
nt_samples_batch_size=nt_samples_batch_size,
stdevs=stdevs,
draw_baseline_from_distrib=draw_baseline_from_distrib,
target=pred_label_idx,
)
validate_result(attributions=attributions)
return attributions
Expand Down
Binary file added example/images/zidane.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
673 changes: 26 additions & 647 deletions example/notebooks/basic_usage.ipynb

Large diffs are not rendered by default.

Binary file added example/yolov5_exmaple/xai.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading