Skip to content

Commit 29bb8f3

Browse files
authored
feat: Added GradCAM and GradCAM++ implementations (#1)
* feat: Added GradCAM implementations * feat: Added visualization utils * chore: Added package __init__ * chore: Added python package setup and requirements * docs: Added sphinx documentation * test: Added unittests * style: Added flake8 config * chore: Added coverage config * docs: Updated readme and contributing * chore: Updated gitignore * chore: Added workflow for package test * chore: Added workflow for doc deployment * chore: Added workflow for Gitpage status * chore: Added workflow for pypi publish * test: Fixed unittests * chore: Fixed test requirement * chore: Updated package requirements * style: Removed white space * test: Updated test requirements * chore: Updated package requirements * chore: Fixed workflow
1 parent e269a93 commit 29bb8f3

27 files changed

+1151
-2
lines changed

.coveragerc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[run]
2+
source = torchcam

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
max-line-length = 120
3+
ignore = F401, E402, E265, F403, W503, W504, F821, W605
4+
exclude = .github, .git, venv*, docs, build

.github/workflows/doc-deploy.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: doc-deploy
2+
on:
3+
push:
4+
branches: master
5+
6+
jobs:
7+
docs-publish:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
with:
12+
persist-credentials: false
13+
- name: Set up Python 3.7
14+
uses: actions/setup-python@v1
15+
with:
16+
python-version: 3.7
17+
architecture: x64
18+
- name: Cache python modules
19+
uses: actions/[email protected]
20+
env:
21+
cache-name: cache-pkg-requirements
22+
with:
23+
path: ~/.cache/pip
24+
key: ${{ runner.os }}-install-${{ env.cache-name }}-${{ hashFiles('requirements.txt') }}
25+
restore-keys: |
26+
${{ runner.os }}-install-${{ env.cache-name }}-
27+
${{ runner.os }}-install-
28+
${{ runner.os }}-
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install -e .
33+
pip install -r docs/requirements.txt
34+
35+
- name: Build documentation
36+
run: |
37+
sphinx-build docs/source docs/build -a
38+
39+
- name: Install SSH Client 🔑
40+
uses: webfactory/[email protected]
41+
with:
42+
ssh-private-key: ${{ secrets.SSH_DEPLOY_KEY }}
43+
44+
- name: Deploy to Github Pages
45+
uses: JamesIves/[email protected]
46+
with:
47+
BRANCH: gh-pages
48+
FOLDER: 'docs/build'
49+
COMMIT_MESSAGE: '[skip ci] Documentation updates'
50+
CLEAN: true
51+
SSH: true
52+

.github/workflows/gh-page.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: GH-Pages Status
2+
on:
3+
page_build
4+
5+
jobs:
6+
see-page-build-payload:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Set up Python 3.7
10+
uses: actions/setup-python@v1
11+
with:
12+
python-version: 3.7
13+
architecture: x64
14+
- name: check status
15+
run: |
16+
import os
17+
status, errormsg = os.getenv('STATUS'), os.getenv('ERROR')
18+
if status != 'built': raise AssertionError(f"There was an error building the page on GitHub pages.\n\nStatus: {status}\n\nError messsage: {errormsg}")
19+
shell: python
20+
env:
21+
STATUS: ${{ github.event.build.status }}
22+
ERROR: ${{ github.event.build.error.message }}

.github/workflows/main.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: python-package
2+
3+
on: push
4+
5+
jobs:
6+
pkg-install:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: Set up Python 3.7
11+
uses: actions/setup-python@v1
12+
with:
13+
python-version: 3.7
14+
architecture: x64
15+
- name: Cache python modules
16+
uses: actions/[email protected]
17+
env:
18+
cache-name: cache-pkg-requirements
19+
with:
20+
path: ~/.cache/pip
21+
key: ${{ runner.os }}-install-${{ env.cache-name }}-${{ hashFiles('requirements.txt') }}
22+
restore-keys: |
23+
${{ runner.os }}-install-${{ env.cache-name }}-
24+
${{ runner.os }}-install-
25+
${{ runner.os }}-
26+
- name: Install package
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install -e .
30+
31+
pkg-test:
32+
runs-on: ubuntu-latest
33+
needs: pkg-install
34+
steps:
35+
- uses: actions/checkout@v2
36+
- name: Set up Python 3.7
37+
uses: actions/setup-python@v1
38+
with:
39+
python-version: 3.7
40+
architecture: x64
41+
- name: Cache python modules
42+
uses: actions/[email protected]
43+
env:
44+
cache-name: cache-pkg-requirements
45+
with:
46+
path: ~/.cache/pip
47+
key: ${{ runner.os }}-install-${{ env.cache-name }}-${{ hashFiles('requirements.txt') }}
48+
restore-keys: |
49+
${{ runner.os }}-install-${{ env.cache-name }}-
50+
${{ runner.os }}-install-
51+
${{ runner.os }}-
52+
- name: Install dependencies
53+
run: |
54+
python -m pip install --upgrade pip
55+
pip install -e .
56+
pip install -r .github/workflows/requirements.txt
57+
58+
- name: Run unittests
59+
run: |
60+
coverage run -m unittest discover test/
61+
coverage xml
62+
63+
- name: Upload coverage to Codecov
64+
uses: codecov/[email protected]
65+
with:
66+
file: ./coverage.xml # optional
67+
flags: unittests # optional
68+
fail_ci_if_error: true # optional (default = false)
69+
70+
flake8-py3:
71+
runs-on: ubuntu-latest
72+
steps:
73+
- uses: actions/checkout@v2
74+
- name: Set up Python 3.7
75+
uses: actions/setup-python@v1
76+
with:
77+
python-version: 3.7
78+
architecture: x64
79+
- name: Run flake8
80+
run: |
81+
pip install flake8
82+
flake8 --version
83+
flake8 ./
84+
85+
docs-build:
86+
runs-on: ubuntu-latest
87+
needs: pkg-install
88+
steps:
89+
- uses: actions/checkout@v2
90+
- name: Set up Python 3.7
91+
uses: actions/setup-python@v1
92+
with:
93+
python-version: 3.7
94+
architecture: x64
95+
- name: Cache python modules
96+
uses: actions/[email protected]
97+
env:
98+
cache-name: cache-pkg-requirements
99+
with:
100+
path: ~/.cache/pip
101+
key: ${{ runner.os }}-install-${{ env.cache-name }}-${{ hashFiles('requirements.txt') }}
102+
restore-keys: |
103+
${{ runner.os }}-install-${{ env.cache-name }}-
104+
${{ runner.os }}-install-
105+
${{ runner.os }}-
106+
- name: Install dependencies
107+
run: |
108+
python -m pip install --upgrade pip
109+
pip install -e .
110+
pip install -r docs/requirements.txt
111+
112+
- name: Build documentation
113+
run: |
114+
sphinx-build docs/source docs/build -a
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: pypi-publish
2+
3+
on:
4+
release:
5+
types: [published, edited]
6+
7+
jobs:
8+
9+
pkg-install:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Set up Python 3.7
14+
uses: actions/setup-python@v1
15+
with:
16+
python-version: 3.7
17+
architecture: x64
18+
- name: Cache python modules
19+
uses: actions/[email protected]
20+
env:
21+
cache-name: cache-pkg-requirements
22+
with:
23+
path: ~/.cache/pip
24+
key: ${{ runner.os }}-install-${{ env.cache-name }}-${{ hashFiles('requirements.txt') }}
25+
restore-keys: |
26+
${{ runner.os }}-install-${{ env.cache-name }}-
27+
${{ runner.os }}-install-
28+
${{ runner.os }}-
29+
- name: Install package
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install -e .
33+
34+
pypi-publish:
35+
runs-on: ubuntu-latest
36+
needs: pkg-install
37+
steps:
38+
- uses: actions/checkout@v2
39+
- name: Set up Python 3.7
40+
uses: actions/setup-python@v1
41+
with:
42+
python-version: 3.7
43+
architecture: x64
44+
- name: Install dependencies
45+
run: |
46+
python -m pip install --upgrade pip
47+
pip install -r requirements.txt
48+
pip install setuptools wheel twine --upgrade
49+
- name: Get release tag
50+
id: release_tag
51+
run: |
52+
echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
53+
- name: Build and publish
54+
env:
55+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
56+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
57+
VERSION: ${{ steps.release_tag.outputs.VERSION }}
58+
run: |
59+
VERSION="${VERSION:1}"
60+
BUILD_VERSION=$VERSION python setup.py sdist bdist_wheel
61+
twine check dist/*
62+
twine upload dist/*

.github/workflows/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage>=4.5.4
2+
requests>=2.20.0
3+
torchvision>=0.4.0

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,6 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
# Package version
132+
torchcam/version.py

CONTRIBUTING.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Contributing to torchcam
2+
3+
Everything you need to know to contribute efficiently to the project.
4+
5+
6+
7+
## Codebase structure
8+
9+
- [torchcam](https://github.com/frgfm/torch-cam/blob/master/torchcam) - The actual torchcam library
10+
- [test](https://github.com/frgfm/torch-cam/blob/master/test) - Python unit tests
11+
12+
13+
14+
## Continuous Integration
15+
16+
This project uses the following integrations to ensure proper codebase maintenance:
17+
18+
- [CircleCI](https://circleci.com/) - run jobs for package build and coverage
19+
- [Codacy](https://www.codacy.com/) - analyzes commits for code quality
20+
- [Codecov](https://codecov.io/) - reports back coverage results
21+
22+
As a contributor, you will only have to ensure coverage of your code by adding appropriate unit testing of your code.
23+
24+
25+
26+
## Issues
27+
28+
Use Github [issues](https://github.com/frgfm/torch-cam/issues) for feature requests, or bug reporting. When doing so, use issue templates whenever possible and provide enough information for other contributors to jump in.
29+
30+
31+
32+
## Developping torchcam
33+
34+
35+
### Commits
36+
37+
- **Code**: ensure to provide docstrings to your Python code. In doing so, please follow [Google-style](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html) so it can ease the process of documentation later.
38+
- **Commit message**: please follow [Udacity guide](http://udacity.github.io/git-styleguide/)

0 commit comments

Comments
 (0)