Skip to content

Commit

Permalink
feat: Remove opencv python (#128)
Browse files Browse the repository at this point in the history
* build: Update dependencies to retain only opencv-python-headless

* build: Upgrade version, update changelog

* test: Skip draem test as it doesn't work with the current anomalib dependency

* refactor: Update gradcam integration code to support the new version
  • Loading branch information
lorenzomammana authored Aug 20, 2024
1 parent 84c0b07 commit 1c4e417
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 139 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.

### [2.2.3]

#### Updated

- Keep only opencv-python-headless as a dependency for quadra to avoid conflicts with the non-headless version

### [2.2.2]

#### Updated
Expand Down
157 changes: 29 additions & 128 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "quadra"
version = "2.2.2"
version = "2.2.3"
description = "Deep Learning experiment orchestration library"
authors = [
"Federico Belotti <[email protected]>",
Expand Down Expand Up @@ -60,7 +60,7 @@ python_dotenv = "~0.21"
rich = "~13.2"
scikit_learn = "~1.2"
pydantic = "1.10.10"
grad_cam = "1.4.6"
grad-cam-orobix = "1.5.3.dev001"
matplotlib = "~3.6"
seaborn = "~0.12"
albumentations = "~1.3"
Expand All @@ -72,7 +72,7 @@ h5py = "~3.8"
timm = "0.9.12"

segmentation_models_pytorch-orobix = "0.3.3.dev1"
anomalib-orobix = "0.7.0.dev140"
anomalib-orobix = "0.7.0.dev141"
xxhash = "~3.2"
torchinfo = "~1.8"
typing_extensions = { version = "4.11.0", python = "<3.10" }
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__ = "2.2.2"
__version__ = "2.2.3"


def get_version():
Expand Down
6 changes: 1 addition & 5 deletions quadra/modules/classification/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,9 @@ def prepare_gradcam(self) -> None:
if isinstance(self.model.features_extractor, timm.models.resnet.ResNet):
target_layers = [cast(BaseNetworkBuilder, self.model).features_extractor.layer4[-1]]

# Get model current device
device = next(self.model.parameters()).device

self.cam = GradCAM(
model=self.model,
target_layers=target_layers,
use_cuda=device.type == "cuda",
)
# Activating gradients
for p in self.model.features_extractor.layer4[-1].parameters():
Expand Down Expand Up @@ -262,7 +258,7 @@ def __init__(
self.gradcam = False
else:
target_layers = [model[0].features_extractor.layer4[-1]]
self.cam = GradCAM(model=model, target_layers=target_layers, use_cuda=torch.cuda.is_available())
self.cam = GradCAM(model=model, target_layers=target_layers)

def forward(self, x):
return self.model(x)
Expand Down
1 change: 0 additions & 1 deletion quadra/tasks/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,6 @@ def prepare_gradcam(self) -> None:
self.cam = GradCAM(
model=self.deployment_model.model,
target_layers=target_layers,
use_cuda=(self.device != "cpu"),
)
for p in self.deployment_model.model.features_extractor.layer4[-1].parameters():
p.requires_grad = True
Expand Down
1 change: 0 additions & 1 deletion quadra/utils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ def get_feature(
cam = GradCAM(
model=feature_extractor,
target_layers=target_layers,
use_cuda=torch.cuda.is_available(),
)
for p in feature_extractor.features_extractor.layer4[-1].parameters():
p.requires_grad = True
Expand Down
4 changes: 4 additions & 0 deletions tests/tasks/test_anomaly.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ def test_fastflow(tmp_path: Path, base_anomaly_dataset: base_anomaly_dataset, ta
shutil.rmtree(tmp_path)


@pytest.mark.skip(
reason="This test requires anomalib with imgaug installed which we don't want to include in the dependencies as it "
"requires the non headless version of opencv-python"
)
@pytest.mark.slow
@pytest.mark.usefixtures("mock_training")
@pytest.mark.parametrize("task", ["classification", "segmentation"])
Expand Down

0 comments on commit 1c4e417

Please sign in to comment.