Skip to content

Commit

Permalink
Update project files (#3)
Browse files Browse the repository at this point in the history
* change point detection module

* release automation

* debug docs

* change docs workflow

* debug workflow

* debug `python-package.yml`

* debug release action

* update project files

* change list_datasets function
  • Loading branch information
edadaltocg authored Feb 23, 2023
1 parent 2937775 commit 682ef2f
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Create new patch release
run: .github/scripts/release.py
run: python .github/scripts/release.py
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,5 @@ dmypy.json

/deprecated
/scripts/bash

.pypirc
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,15 @@ Under development.

## Deployment & Documentation & Stats & License

[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/edadaltocg/detectors/graphs/commit-activity)
[![PyPi version](https://badgen.net/pypi/v/pip/)](https://pypi.org/project/pip)

[![build](https://github.com/edadaltocg/detectors/actions/workflows/python-package.yml/badge.svg)](https://github.com/edadaltocg/detectors/actions/workflows/python-package.yml)
[![Documentation Status](https://readthedocs.org/projects/ansicolortags/badge/?version=latest)](http://ansicolortags.readthedocs.io/?badge=latest)

[![GitHub stars](https://img.shields.io/github/stars/Naereen/StrapDown.js.svg?style=social&label=Star&maxAge=2592000)](https://GitHub.com/Naereen/StrapDown.js/stargazers/)


[![GitHub forks](https://badgen.net/github/forks/Naereen/Strapdown.js/)](https://GitHub.com/Naereen/StrapDown.js/network/)

[![GitHub stars](https://img.shields.io/github/stars/edadaltocg/detectors.svg?style=social&label=Star&maxAge=2592000)](https://GitHub.com/edadaltocg/detectors/stargazers/)
[![GitHub forks](https://badgen.net/github/forks/edadaltocg/detectors/)](https://github.com/edadaltocg/detectors/network/)
[![PyPI download month](https://img.shields.io/pypi/dm/ansicolortags.svg)](https://pypi.python.org/pypi/ansicolortags/)

[![GitHub contributors](https://img.shields.io/github/contributors/Naereen/badges.svg)](https://GitHub.com/Naereen/badges/graphs/contributors/)

[![DOI:10.1007/978-3-319-76207-4_15](https://zenodo.org/badge/DOI/10.1007/978-3-319-76207-4_15.svg)](https://doi.org/10.1007/978-3-319-76207-4_15)

[![PyPi license](https://badgen.net/pypi/license/pip/)](https://pypi.org/project/pip/)

-----
Expand All @@ -53,6 +47,26 @@ Under development.
pip install detectors
```

## Thanks to all our contributors

<a href="https://github.com/edadaltocg/detectors/graphs/contributors">
<img src="https://contributors-img.web.app/image?repo=edadaltocg/detectors" />
</a>

### Contact

Concerning this package, its use and bugs, use the [issue page](https://github.com/edadaltocg/detectors/issues) of the [ruptures repository](https://github.com/edadaltocg/detectors). For other inquiries, you can contact me [here](https://edadaltocg.github.io/contact/).


### Important links

- [Documentation]()
- [Pypi package index](https://pypi.python.org/pypi/detectors)

### Changelog

See the [changelog](https://github.com/edadaltocg/detectors/blob/master/CHANGELOG.md) for a history of notable changes to `detectors`.

<!-- ## TODO
- Pipeline for generating results table.
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[build-system]
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]

[tool.isort]
atomic = true
profile = "black"
Expand Down
3 changes: 2 additions & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
setuptools
setuptools_scm
black
isort
pytest
pytest-cov
pytest-timeout
pytest-xdist
coverage
twine
sphinx
six
Expand Down
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

setup(
name="detectors",
version="0.1.0",
author="Eduardo Dadalto with the help of all our contributors.",
author_email="[email protected]",
description="Out of distribution detection benchmark.",
Expand All @@ -36,7 +35,6 @@
python_requires=">=3.8.0",
install_requires=install_requires,
classifiers=[
# "Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Intended Audience :: Education",
"Intended Audience :: Science/Research",
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import config, data, models
from .data import create_dataset, get_dataset_cls, get_datasets_names
from .data import create_dataset, get_dataset_cls, list_datasets
from .methods.ood import create_ood_detector
from .pipelines import create_pipeline
5 changes: 4 additions & 1 deletion src/detectors/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
"cifar10c": CIFAR10_C,
"cifar100c": CIFAR100_C,
"imagenet1kc": ...,
"oxford_pets": ...,
"oxford_flowers": ...,
"cub200": ...,
}


Expand Down Expand Up @@ -89,5 +92,5 @@ def get_dataset_cls(dataset_name: str) -> Type[Dataset]:
return datasets_registry[dataset_name]


def get_datasets_names():
def list_datasets():
return list(datasets_registry.keys())
1 change: 0 additions & 1 deletion src/detectors/methods/cpd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from detectors.methods.cpd.pelt import PeltL2


cpd_registry = {
"peltl2": PeltL2,
}
Expand Down
1 change: 1 addition & 0 deletions src/detectors/methods/cpd/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
From `https://github.com/deepcharles/ruptures/blob/master/src/ruptures/base.py`
"""
import abc

from .utils import pairwise


Expand Down
1 change: 1 addition & 0 deletions src/detectors/methods/cpd/pelt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from `https://github.com/deepcharles/ruptures/blob/master/src/ruptures/detection/pelt.py`"""
from math import floor

from .base import BaseCost, BaseEstimator


Expand Down
1 change: 1 addition & 0 deletions src/detectors/methods/cpd/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from itertools import tee

import numpy as np


Expand Down
1 change: 1 addition & 0 deletions src/detectors/methods/ood/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"rankfeat": ...,
"vim": ...,
"kl_logits": ...,
"mls": ...,
}


Expand Down
15 changes: 10 additions & 5 deletions src/detectors/methods/ood/mahalanobis.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ def __init__(
) -> None:
self.model = model
self.features_nodes = features_nodes
if self.features_nodes is None:
self.features_nodes = [self.model.feature_info[-1]["module"]]
self.feature_extractor = create_feature_extractor(self.model, self.features_nodes)
if self.features_nodes is not None:
self.feature_extractor = create_feature_extractor(self.model, self.features_nodes)
self.reduction_method = inv_mat_method
self.aggregation_method = aggregation_method
if aggregation_method is not None and features_nodes is not None and len(features_nodes) > 1:
Expand All @@ -163,7 +162,10 @@ def start(self, *args, **kwargs):

@torch.no_grad()
def update(self, x: Tensor, y: Tensor) -> None:
features = self.feature_extractor(x)
if self.features_nodes is None:
features = {"penultimate": self.model.forward_features(x)}
else:
features = self.feature_extractor(x)

for k in features:
features[k] = self.pooling_op(features[k])
Expand Down Expand Up @@ -196,7 +198,10 @@ def __call__(self, x: Tensor) -> Tensor:
raise ValueError("You must properly fit the Mahalanobis method first.")

with torch.no_grad():
features = self.feature_extractor(x)
if self.features_nodes is None:
features = {"penultimate": self.model.forward_features(x)}
else:
features = self.feature_extractor(x)

for k in features:
features[k] = self.pooling_op(features[k])
Expand Down
6 changes: 5 additions & 1 deletion src/detectors/models/vgg.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ def _create_vgg_small(variant, features_dim=512, pretrained=False, **kwargs):
# load weights
if pretrained:
checkpoint = model.default_cfg.url
model.load_state_dict(torch.hub.load_state_dict_from_url(checkpoint, progress=True, map_location="cpu", file_name=f"{variant}.pth"))
model.load_state_dict(
torch.hub.load_state_dict_from_url(
checkpoint, progress=True, map_location="cpu", file_name=f"{variant}.pth"
)
)

return model

Expand Down
2 changes: 1 addition & 1 deletion tests/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import torchvision.transforms as transforms

import detectors
from detectors import create_dataset, get_dataset_cls, get_datasets_names
from detectors import create_dataset, get_dataset_cls, list_datasets
from detectors.config import DATA_DIR, IMAGENET_ROOT
from detectors.data.cifar_wrapper import CIFAR10Wrapped, CIFAR100Wrapped

Expand Down

0 comments on commit 682ef2f

Please sign in to comment.