diff --git a/.buildinfo b/.buildinfo index dcd75e5..527fb8a 100644 --- a/.buildinfo +++ b/.buildinfo @@ -1,4 +1,4 @@ # Sphinx build info version 1 # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. -config: 474b23a2edc3936fbc65d7811ba6f6f3 +config: cd8740786265d3c259316800322faaf6 tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/.doctrees/changelog.doctree b/.doctrees/changelog.doctree index e50eddc..0881885 100644 Binary files a/.doctrees/changelog.doctree and b/.doctrees/changelog.doctree differ diff --git a/.doctrees/environment.pickle b/.doctrees/environment.pickle index ca386d8..462fa15 100644 Binary files a/.doctrees/environment.pickle and b/.doctrees/environment.pickle differ diff --git a/.doctrees/index.doctree b/.doctrees/index.doctree index 6f064bd..2cc5ead 100644 Binary files a/.doctrees/index.doctree and b/.doctrees/index.doctree differ diff --git a/.doctrees/installing.doctree b/.doctrees/installing.doctree index c73d6a0..66ba399 100644 Binary files a/.doctrees/installing.doctree and b/.doctrees/installing.doctree differ diff --git a/.doctrees/methods.doctree b/.doctrees/methods.doctree index 1593cbc..1b07eb0 100644 Binary files a/.doctrees/methods.doctree and b/.doctrees/methods.doctree differ diff --git a/.doctrees/metrics.doctree b/.doctrees/metrics.doctree index 1026aa4..b0a85f5 100644 Binary files a/.doctrees/metrics.doctree and b/.doctrees/metrics.doctree differ diff --git a/.doctrees/notebooks.doctree b/.doctrees/notebooks.doctree index effa898..29b3159 100644 Binary files a/.doctrees/notebooks.doctree and b/.doctrees/notebooks.doctree differ diff --git a/.doctrees/utils.doctree b/.doctrees/utils.doctree index 6706276..68d38be 100644 Binary files a/.doctrees/utils.doctree and b/.doctrees/utils.doctree differ diff --git a/_modules/index.html b/_modules/index.html index 81d75c7..f71592f 100644 --- a/_modules/index.html +++ b/_modules/index.html @@ -13,7 +13,7 @@ - + Overview: module code - TorchCAM @@ -256,7 +256,7 @@

All modules for which code is available

- + diff --git a/_modules/torchcam/methods/activation.html b/_modules/torchcam/methods/activation.html index 8dc015a..0073003 100644 --- a/_modules/torchcam/methods/activation.html +++ b/_modules/torchcam/methods/activation.html @@ -13,7 +13,7 @@ - + torchcam.methods.activation - TorchCAM @@ -681,7 +681,7 @@

Source code for torchcam.methods.activation

     
   
- + diff --git a/_modules/torchcam/methods/gradient.html b/_modules/torchcam/methods/gradient.html index 20fe14e..9592e1f 100644 --- a/_modules/torchcam/methods/gradient.html +++ b/_modules/torchcam/methods/gradient.html @@ -13,7 +13,7 @@ - + torchcam.methods.gradient - TorchCAM @@ -660,7 +660,7 @@

Source code for torchcam.methods.gradient

     
   
- + diff --git a/_modules/torchcam/metrics.html b/_modules/torchcam/metrics.html index 58f242b..2f68a0d 100644 --- a/_modules/torchcam/metrics.html +++ b/_modules/torchcam/metrics.html @@ -13,7 +13,7 @@ - + torchcam.metrics - TorchCAM @@ -394,7 +394,7 @@

Source code for torchcam.metrics

     
   
- + diff --git a/_modules/torchcam/utils.html b/_modules/torchcam/utils.html index 73271ab..66fc8bd 100644 --- a/_modules/torchcam/utils.html +++ b/_modules/torchcam/utils.html @@ -13,7 +13,7 @@ - + torchcam.utils - TorchCAM @@ -302,7 +302,7 @@

Source code for torchcam.utils

     
   
- + diff --git a/_static/basic.css b/_static/basic.css index 30fee9d..f316efc 100644 --- a/_static/basic.css +++ b/_static/basic.css @@ -4,7 +4,7 @@ * * Sphinx stylesheet -- basic theme. * - * :copyright: Copyright 2007-2023 by the Sphinx team, see AUTHORS. + * :copyright: Copyright 2007-2024 by the Sphinx team, see AUTHORS. * :license: BSD, see LICENSE for details. * */ diff --git a/_static/doctools.js b/_static/doctools.js index d06a71d..4d67807 100644 --- a/_static/doctools.js +++ b/_static/doctools.js @@ -4,7 +4,7 @@ * * Base JavaScript utilities for all Sphinx HTML documentation. * - * :copyright: Copyright 2007-2023 by the Sphinx team, see AUTHORS. + * :copyright: Copyright 2007-2024 by the Sphinx team, see AUTHORS. * :license: BSD, see LICENSE for details. * */ diff --git a/_static/language_data.js b/_static/language_data.js index 250f566..367b8ed 100644 --- a/_static/language_data.js +++ b/_static/language_data.js @@ -5,7 +5,7 @@ * This script contains the language-specific data used by searchtools.js, * namely the list of stopwords, stemmer, scorer and splitter. * - * :copyright: Copyright 2007-2023 by the Sphinx team, see AUTHORS. + * :copyright: Copyright 2007-2024 by the Sphinx team, see AUTHORS. * :license: BSD, see LICENSE for details. * */ @@ -13,7 +13,7 @@ var stopwords = ["a", "and", "are", "as", "at", "be", "but", "by", "for", "if", "in", "into", "is", "it", "near", "no", "not", "of", "on", "or", "such", "that", "the", "their", "then", "there", "these", "they", "this", "to", "was", "will", "with"]; -/* Non-minified version is copied as a separate JS file, is available */ +/* Non-minified version is copied as a separate JS file, if available */ /** * Porter Stemmer diff --git a/_static/searchtools.js b/_static/searchtools.js index 7918c3f..92da3f8 100644 --- a/_static/searchtools.js +++ b/_static/searchtools.js @@ -4,7 +4,7 @@ * * Sphinx JavaScript utilities for the full-text search. * - * :copyright: Copyright 2007-2023 by the Sphinx team, see AUTHORS. + * :copyright: Copyright 2007-2024 by the Sphinx team, see AUTHORS. * :license: BSD, see LICENSE for details. * */ @@ -99,7 +99,7 @@ const _displayItem = (item, searchTerms, highlightTerms) => { .then((data) => { if (data) listItem.appendChild( - Search.makeSearchSummary(data, searchTerms) + Search.makeSearchSummary(data, searchTerms, anchor) ); // highlight search terms in the summary if (SPHINX_HIGHLIGHT_ENABLED) // set in sphinx_highlight.js @@ -116,8 +116,8 @@ const _finishSearch = (resultCount) => { ); else Search.status.innerText = _( - `Search finished, found ${resultCount} page(s) matching the search query.` - ); + "Search finished, found ${resultCount} page(s) matching the search query." + ).replace('${resultCount}', resultCount); }; const _displayNextItem = ( results, @@ -137,6 +137,22 @@ const _displayNextItem = ( // search finished, update title and status message else _finishSearch(resultCount); }; +// Helper function used by query() to order search results. +// Each input is an array of [docname, title, anchor, descr, score, filename]. +// Order the results by score (in opposite order of appearance, since the +// `_displayNextItem` function uses pop() to retrieve items) and then alphabetically. +const _orderResultsByScoreThenName = (a, b) => { + const leftScore = a[4]; + const rightScore = b[4]; + if (leftScore === rightScore) { + // same score: sort alphabetically + const leftTitle = a[1].toLowerCase(); + const rightTitle = b[1].toLowerCase(); + if (leftTitle === rightTitle) return 0; + return leftTitle > rightTitle ? -1 : 1; // inverted is intentional + } + return leftScore > rightScore ? 1 : -1; +}; /** * Default splitQuery function. Can be overridden in ``sphinx.search`` with a @@ -160,13 +176,26 @@ const Search = { _queued_query: null, _pulse_status: -1, - htmlToText: (htmlString) => { + htmlToText: (htmlString, anchor) => { const htmlElement = new DOMParser().parseFromString(htmlString, 'text/html'); - htmlElement.querySelectorAll(".headerlink").forEach((el) => { el.remove() }); + for (const removalQuery of [".headerlinks", "script", "style"]) { + htmlElement.querySelectorAll(removalQuery).forEach((el) => { el.remove() }); + } + if (anchor) { + const anchorContent = htmlElement.querySelector(`[role="main"] ${anchor}`); + if (anchorContent) return anchorContent.textContent; + + console.warn( + `Anchored content block not found. Sphinx search tries to obtain it via DOM query '[role=main] ${anchor}'. Check your theme or template.` + ); + } + + // if anchor not specified or not found, fall back to main content const docContent = htmlElement.querySelector('[role="main"]'); - if (docContent !== undefined) return docContent.textContent; + if (docContent) return docContent.textContent; + console.warn( - "Content block not found. Sphinx search tries to obtain it via '[role=main]'. Could you check your theme or template." + "Content block not found. Sphinx search tries to obtain it via DOM query '[role=main]'. Check your theme or template." ); return ""; }, @@ -239,16 +268,7 @@ const Search = { else Search.deferQuery(query); }, - /** - * execute search (requires search index to be loaded) - */ - query: (query) => { - const filenames = Search._index.filenames; - const docNames = Search._index.docnames; - const titles = Search._index.titles; - const allTitles = Search._index.alltitles; - const indexEntries = Search._index.indexentries; - + _parseQuery: (query) => { // stem the search terms and add them to the correct list const stemmer = new Stemmer(); const searchTerms = new Set(); @@ -284,16 +304,32 @@ const Search = { // console.info("required: ", [...searchTerms]); // console.info("excluded: ", [...excludedTerms]); - // array of [docname, title, anchor, descr, score, filename] - let results = []; + return [query, searchTerms, excludedTerms, highlightTerms, objectTerms]; + }, + + /** + * execute search (requires search index to be loaded) + */ + _performSearch: (query, searchTerms, excludedTerms, highlightTerms, objectTerms) => { + const filenames = Search._index.filenames; + const docNames = Search._index.docnames; + const titles = Search._index.titles; + const allTitles = Search._index.alltitles; + const indexEntries = Search._index.indexentries; + + // Collect multiple result groups to be sorted separately and then ordered. + // Each is an array of [docname, title, anchor, descr, score, filename]. + const normalResults = []; + const nonMainIndexResults = []; + _removeChildren(document.getElementById("search-progress")); - const queryLower = query.toLowerCase(); + const queryLower = query.toLowerCase().trim(); for (const [title, foundTitles] of Object.entries(allTitles)) { - if (title.toLowerCase().includes(queryLower) && (queryLower.length >= title.length/2)) { + if (title.toLowerCase().trim().includes(queryLower) && (queryLower.length >= title.length/2)) { for (const [file, id] of foundTitles) { let score = Math.round(100 * queryLower.length / title.length) - results.push([ + normalResults.push([ docNames[file], titles[file] !== title ? `${titles[file]} > ${title}` : title, id !== null ? "#" + id : "", @@ -308,46 +344,47 @@ const Search = { // search for explicit entries in index directives for (const [entry, foundEntries] of Object.entries(indexEntries)) { if (entry.includes(queryLower) && (queryLower.length >= entry.length/2)) { - for (const [file, id] of foundEntries) { - let score = Math.round(100 * queryLower.length / entry.length) - results.push([ + for (const [file, id, isMain] of foundEntries) { + const score = Math.round(100 * queryLower.length / entry.length); + const result = [ docNames[file], titles[file], id ? "#" + id : "", null, score, filenames[file], - ]); + ]; + if (isMain) { + normalResults.push(result); + } else { + nonMainIndexResults.push(result); + } } } } // lookup as object objectTerms.forEach((term) => - results.push(...Search.performObjectSearch(term, objectTerms)) + normalResults.push(...Search.performObjectSearch(term, objectTerms)) ); // lookup as search terms in fulltext - results.push(...Search.performTermsSearch(searchTerms, excludedTerms)); + normalResults.push(...Search.performTermsSearch(searchTerms, excludedTerms)); // let the scorer override scores with a custom scoring function - if (Scorer.score) results.forEach((item) => (item[4] = Scorer.score(item))); - - // now sort the results by score (in opposite order of appearance, since the - // display function below uses pop() to retrieve items) and then - // alphabetically - results.sort((a, b) => { - const leftScore = a[4]; - const rightScore = b[4]; - if (leftScore === rightScore) { - // same score: sort alphabetically - const leftTitle = a[1].toLowerCase(); - const rightTitle = b[1].toLowerCase(); - if (leftTitle === rightTitle) return 0; - return leftTitle > rightTitle ? -1 : 1; // inverted is intentional - } - return leftScore > rightScore ? 1 : -1; - }); + if (Scorer.score) { + normalResults.forEach((item) => (item[4] = Scorer.score(item))); + nonMainIndexResults.forEach((item) => (item[4] = Scorer.score(item))); + } + + // Sort each group of results by score and then alphabetically by name. + normalResults.sort(_orderResultsByScoreThenName); + nonMainIndexResults.sort(_orderResultsByScoreThenName); + + // Combine the result groups in (reverse) order. + // Non-main index entries are typically arbitrary cross-references, + // so display them after other results. + let results = [...nonMainIndexResults, ...normalResults]; // remove duplicate search results // note the reversing of results, so that in the case of duplicates, the highest-scoring entry is kept @@ -361,7 +398,12 @@ const Search = { return acc; }, []); - results = results.reverse(); + return results.reverse(); + }, + + query: (query) => { + const [searchQuery, searchTerms, excludedTerms, highlightTerms, objectTerms] = Search._parseQuery(query); + const results = Search._performSearch(searchQuery, searchTerms, excludedTerms, highlightTerms, objectTerms); // for debugging //Search.lastresults = results.slice(); // a copy @@ -466,14 +508,18 @@ const Search = { // add support for partial matches if (word.length > 2) { const escapedWord = _escapeRegExp(word); - Object.keys(terms).forEach((term) => { - if (term.match(escapedWord) && !terms[word]) - arr.push({ files: terms[term], score: Scorer.partialTerm }); - }); - Object.keys(titleTerms).forEach((term) => { - if (term.match(escapedWord) && !titleTerms[word]) - arr.push({ files: titleTerms[word], score: Scorer.partialTitle }); - }); + if (!terms.hasOwnProperty(word)) { + Object.keys(terms).forEach((term) => { + if (term.match(escapedWord)) + arr.push({ files: terms[term], score: Scorer.partialTerm }); + }); + } + if (!titleTerms.hasOwnProperty(word)) { + Object.keys(titleTerms).forEach((term) => { + if (term.match(escapedWord)) + arr.push({ files: titleTerms[term], score: Scorer.partialTitle }); + }); + } } // no match but word was a required one @@ -496,9 +542,8 @@ const Search = { // create the mapping files.forEach((file) => { - if (fileMap.has(file) && fileMap.get(file).indexOf(word) === -1) - fileMap.get(file).push(word); - else fileMap.set(file, [word]); + if (!fileMap.has(file)) fileMap.set(file, [word]); + else if (fileMap.get(file).indexOf(word) === -1) fileMap.get(file).push(word); }); }); @@ -549,8 +594,8 @@ const Search = { * search summary for a given text. keywords is a list * of stemmed words. */ - makeSearchSummary: (htmlText, keywords) => { - const text = Search.htmlToText(htmlText); + makeSearchSummary: (htmlText, keywords, anchor) => { + const text = Search.htmlToText(htmlText, anchor); if (text === "") return null; const textLower = text.toLowerCase(); diff --git a/changelog.html b/changelog.html index 9505053..432eb0a 100644 --- a/changelog.html +++ b/changelog.html @@ -14,7 +14,7 @@ - + Changelog - TorchCAM @@ -222,33 +222,33 @@
-

Changelog#

+

Changelog

-

v0.3.2 (2022-08-02)#

+

v0.3.2 (2022-08-02)

Release note: v0.3.2

-

v0.3.1 (2021-10-31)#

+

v0.3.1 (2021-10-31)

Release note: v0.3.1

-

v0.3.0 (2021-10-31)#

+

v0.3.0 (2021-10-31)

Release note: v0.3.0

-

v0.2.0 (2021-04-10)#

+

v0.2.0 (2021-04-10)

Release note: v0.2.0

-

v0.1.2 (2020-12-27)#

+

v0.1.2 (2020-12-27)

Release note: v0.1.2

-

v0.1.1 (2020-08-03)#

+

v0.1.1 (2020-08-03)

Release note: v0.1.1

-

v0.1.0 (2020-03-24)#

+

v0.1.0 (2020-03-24)

Release note: v0.1.0

@@ -327,7 +327,7 @@

v0.1.0 (2020-03-24) - + diff --git a/genindex.html b/genindex.html index cb75cf2..b948581 100644 --- a/genindex.html +++ b/genindex.html @@ -13,7 +13,7 @@ - Index - TorchCAM + Index - TorchCAM @@ -361,7 +361,7 @@

X

- + diff --git a/index.html b/index.html index 2e16210..7b82c29 100644 --- a/index.html +++ b/index.html @@ -14,7 +14,7 @@ - + TorchCAM @@ -222,7 +222,7 @@
-

TorchCAM: class activation explorer#

+

TorchCAM: class activation explorer

TorchCAM provides a minimal yet flexible way to explore the spatial importance of features on your PyTorch model outputs. Check out the live demo on HuggingFace Spaces 🤗

code_snippet

This project is meant for:

@@ -233,9 +233,9 @@

TorchCAM: class activation explorer
-

CAM zoo#

+

CAM zoo

-

Activation-based methods#

+

Activation-based methods

- + + \ No newline at end of file diff --git a/installing.html b/installing.html index 3841fca..26a0295 100644 --- a/installing.html +++ b/installing.html @@ -14,7 +14,7 @@ - + Installation - TorchCAM @@ -222,24 +222,24 @@
-

Installation#

+

Installation

This library requires Python 3.8 or higher.

-

Via Python Package#

+

Via Python Package

Install the last stable release of the package using pip:

pip install torchcam
 
-

Via Conda#

+

Via Conda

Install the last stable release of the package using conda:

conda install -c frgfm torchcam
 
-

Via Git#

+

Via Git

Install the library in developer mode:

git clone https://github.com/frgfm/torch-cam.git
 pip install -e torch-cam/.
@@ -326,7 +326,7 @@ 

Via Git#<

- + diff --git a/latest/.buildinfo b/latest/.buildinfo index dcd75e5..527fb8a 100644 --- a/latest/.buildinfo +++ b/latest/.buildinfo @@ -1,4 +1,4 @@ # Sphinx build info version 1 # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. -config: 474b23a2edc3936fbc65d7811ba6f6f3 +config: cd8740786265d3c259316800322faaf6 tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/latest/.doctrees/changelog.doctree b/latest/.doctrees/changelog.doctree index a54a2e5..e0c3411 100644 Binary files a/latest/.doctrees/changelog.doctree and b/latest/.doctrees/changelog.doctree differ diff --git a/latest/.doctrees/environment.pickle b/latest/.doctrees/environment.pickle index efeb475..0e289d2 100644 Binary files a/latest/.doctrees/environment.pickle and b/latest/.doctrees/environment.pickle differ diff --git a/latest/.doctrees/index.doctree b/latest/.doctrees/index.doctree index 6f064bd..2cc5ead 100644 Binary files a/latest/.doctrees/index.doctree and b/latest/.doctrees/index.doctree differ diff --git a/latest/.doctrees/installing.doctree b/latest/.doctrees/installing.doctree index c73d6a0..66ba399 100644 Binary files a/latest/.doctrees/installing.doctree and b/latest/.doctrees/installing.doctree differ diff --git a/latest/.doctrees/methods.doctree b/latest/.doctrees/methods.doctree index 1593cbc..1b07eb0 100644 Binary files a/latest/.doctrees/methods.doctree and b/latest/.doctrees/methods.doctree differ diff --git a/latest/.doctrees/metrics.doctree b/latest/.doctrees/metrics.doctree index 1026aa4..b0a85f5 100644 Binary files a/latest/.doctrees/metrics.doctree and b/latest/.doctrees/metrics.doctree differ diff --git a/latest/.doctrees/notebooks.doctree b/latest/.doctrees/notebooks.doctree index effa898..29b3159 100644 Binary files a/latest/.doctrees/notebooks.doctree and b/latest/.doctrees/notebooks.doctree differ diff --git a/latest/.doctrees/utils.doctree b/latest/.doctrees/utils.doctree index 6706276..68d38be 100644 Binary files a/latest/.doctrees/utils.doctree and b/latest/.doctrees/utils.doctree differ diff --git a/latest/_modules/index.html b/latest/_modules/index.html index 670e065..9487abb 100644 --- a/latest/_modules/index.html +++ b/latest/_modules/index.html @@ -13,7 +13,7 @@ - + Overview: module code - TorchCAM @@ -256,7 +256,7 @@

All modules for which code is available

- + diff --git a/latest/_modules/torchcam/methods/activation.html b/latest/_modules/torchcam/methods/activation.html index 26f9089..109aad6 100644 --- a/latest/_modules/torchcam/methods/activation.html +++ b/latest/_modules/torchcam/methods/activation.html @@ -13,7 +13,7 @@ - + torchcam.methods.activation - TorchCAM @@ -686,7 +686,7 @@

Source code for torchcam.methods.activation

     
   
- + diff --git a/latest/_modules/torchcam/methods/gradient.html b/latest/_modules/torchcam/methods/gradient.html index d58d952..b61f604 100644 --- a/latest/_modules/torchcam/methods/gradient.html +++ b/latest/_modules/torchcam/methods/gradient.html @@ -13,7 +13,7 @@ - + torchcam.methods.gradient - TorchCAM @@ -674,7 +674,7 @@

Source code for torchcam.methods.gradient

     
   
- + diff --git a/latest/_modules/torchcam/metrics.html b/latest/_modules/torchcam/metrics.html index 78d1f9d..7e0b483 100644 --- a/latest/_modules/torchcam/metrics.html +++ b/latest/_modules/torchcam/metrics.html @@ -13,7 +13,7 @@ - + torchcam.metrics - TorchCAM @@ -403,7 +403,7 @@

Source code for torchcam.metrics

     
   
- + diff --git a/latest/_modules/torchcam/utils.html b/latest/_modules/torchcam/utils.html index 9d4168d..a6bbf17 100644 --- a/latest/_modules/torchcam/utils.html +++ b/latest/_modules/torchcam/utils.html @@ -13,7 +13,7 @@ - + torchcam.utils - TorchCAM @@ -302,7 +302,7 @@

Source code for torchcam.utils

     
   
- + diff --git a/latest/_static/basic.css b/latest/_static/basic.css index 30fee9d..f316efc 100644 --- a/latest/_static/basic.css +++ b/latest/_static/basic.css @@ -4,7 +4,7 @@ * * Sphinx stylesheet -- basic theme. * - * :copyright: Copyright 2007-2023 by the Sphinx team, see AUTHORS. + * :copyright: Copyright 2007-2024 by the Sphinx team, see AUTHORS. * :license: BSD, see LICENSE for details. * */ diff --git a/latest/_static/doctools.js b/latest/_static/doctools.js index d06a71d..4d67807 100644 --- a/latest/_static/doctools.js +++ b/latest/_static/doctools.js @@ -4,7 +4,7 @@ * * Base JavaScript utilities for all Sphinx HTML documentation. * - * :copyright: Copyright 2007-2023 by the Sphinx team, see AUTHORS. + * :copyright: Copyright 2007-2024 by the Sphinx team, see AUTHORS. * :license: BSD, see LICENSE for details. * */ diff --git a/latest/_static/language_data.js b/latest/_static/language_data.js index 250f566..367b8ed 100644 --- a/latest/_static/language_data.js +++ b/latest/_static/language_data.js @@ -5,7 +5,7 @@ * This script contains the language-specific data used by searchtools.js, * namely the list of stopwords, stemmer, scorer and splitter. * - * :copyright: Copyright 2007-2023 by the Sphinx team, see AUTHORS. + * :copyright: Copyright 2007-2024 by the Sphinx team, see AUTHORS. * :license: BSD, see LICENSE for details. * */ @@ -13,7 +13,7 @@ var stopwords = ["a", "and", "are", "as", "at", "be", "but", "by", "for", "if", "in", "into", "is", "it", "near", "no", "not", "of", "on", "or", "such", "that", "the", "their", "then", "there", "these", "they", "this", "to", "was", "will", "with"]; -/* Non-minified version is copied as a separate JS file, is available */ +/* Non-minified version is copied as a separate JS file, if available */ /** * Porter Stemmer diff --git a/latest/_static/searchtools.js b/latest/_static/searchtools.js index 7918c3f..92da3f8 100644 --- a/latest/_static/searchtools.js +++ b/latest/_static/searchtools.js @@ -4,7 +4,7 @@ * * Sphinx JavaScript utilities for the full-text search. * - * :copyright: Copyright 2007-2023 by the Sphinx team, see AUTHORS. + * :copyright: Copyright 2007-2024 by the Sphinx team, see AUTHORS. * :license: BSD, see LICENSE for details. * */ @@ -99,7 +99,7 @@ const _displayItem = (item, searchTerms, highlightTerms) => { .then((data) => { if (data) listItem.appendChild( - Search.makeSearchSummary(data, searchTerms) + Search.makeSearchSummary(data, searchTerms, anchor) ); // highlight search terms in the summary if (SPHINX_HIGHLIGHT_ENABLED) // set in sphinx_highlight.js @@ -116,8 +116,8 @@ const _finishSearch = (resultCount) => { ); else Search.status.innerText = _( - `Search finished, found ${resultCount} page(s) matching the search query.` - ); + "Search finished, found ${resultCount} page(s) matching the search query." + ).replace('${resultCount}', resultCount); }; const _displayNextItem = ( results, @@ -137,6 +137,22 @@ const _displayNextItem = ( // search finished, update title and status message else _finishSearch(resultCount); }; +// Helper function used by query() to order search results. +// Each input is an array of [docname, title, anchor, descr, score, filename]. +// Order the results by score (in opposite order of appearance, since the +// `_displayNextItem` function uses pop() to retrieve items) and then alphabetically. +const _orderResultsByScoreThenName = (a, b) => { + const leftScore = a[4]; + const rightScore = b[4]; + if (leftScore === rightScore) { + // same score: sort alphabetically + const leftTitle = a[1].toLowerCase(); + const rightTitle = b[1].toLowerCase(); + if (leftTitle === rightTitle) return 0; + return leftTitle > rightTitle ? -1 : 1; // inverted is intentional + } + return leftScore > rightScore ? 1 : -1; +}; /** * Default splitQuery function. Can be overridden in ``sphinx.search`` with a @@ -160,13 +176,26 @@ const Search = { _queued_query: null, _pulse_status: -1, - htmlToText: (htmlString) => { + htmlToText: (htmlString, anchor) => { const htmlElement = new DOMParser().parseFromString(htmlString, 'text/html'); - htmlElement.querySelectorAll(".headerlink").forEach((el) => { el.remove() }); + for (const removalQuery of [".headerlinks", "script", "style"]) { + htmlElement.querySelectorAll(removalQuery).forEach((el) => { el.remove() }); + } + if (anchor) { + const anchorContent = htmlElement.querySelector(`[role="main"] ${anchor}`); + if (anchorContent) return anchorContent.textContent; + + console.warn( + `Anchored content block not found. Sphinx search tries to obtain it via DOM query '[role=main] ${anchor}'. Check your theme or template.` + ); + } + + // if anchor not specified or not found, fall back to main content const docContent = htmlElement.querySelector('[role="main"]'); - if (docContent !== undefined) return docContent.textContent; + if (docContent) return docContent.textContent; + console.warn( - "Content block not found. Sphinx search tries to obtain it via '[role=main]'. Could you check your theme or template." + "Content block not found. Sphinx search tries to obtain it via DOM query '[role=main]'. Check your theme or template." ); return ""; }, @@ -239,16 +268,7 @@ const Search = { else Search.deferQuery(query); }, - /** - * execute search (requires search index to be loaded) - */ - query: (query) => { - const filenames = Search._index.filenames; - const docNames = Search._index.docnames; - const titles = Search._index.titles; - const allTitles = Search._index.alltitles; - const indexEntries = Search._index.indexentries; - + _parseQuery: (query) => { // stem the search terms and add them to the correct list const stemmer = new Stemmer(); const searchTerms = new Set(); @@ -284,16 +304,32 @@ const Search = { // console.info("required: ", [...searchTerms]); // console.info("excluded: ", [...excludedTerms]); - // array of [docname, title, anchor, descr, score, filename] - let results = []; + return [query, searchTerms, excludedTerms, highlightTerms, objectTerms]; + }, + + /** + * execute search (requires search index to be loaded) + */ + _performSearch: (query, searchTerms, excludedTerms, highlightTerms, objectTerms) => { + const filenames = Search._index.filenames; + const docNames = Search._index.docnames; + const titles = Search._index.titles; + const allTitles = Search._index.alltitles; + const indexEntries = Search._index.indexentries; + + // Collect multiple result groups to be sorted separately and then ordered. + // Each is an array of [docname, title, anchor, descr, score, filename]. + const normalResults = []; + const nonMainIndexResults = []; + _removeChildren(document.getElementById("search-progress")); - const queryLower = query.toLowerCase(); + const queryLower = query.toLowerCase().trim(); for (const [title, foundTitles] of Object.entries(allTitles)) { - if (title.toLowerCase().includes(queryLower) && (queryLower.length >= title.length/2)) { + if (title.toLowerCase().trim().includes(queryLower) && (queryLower.length >= title.length/2)) { for (const [file, id] of foundTitles) { let score = Math.round(100 * queryLower.length / title.length) - results.push([ + normalResults.push([ docNames[file], titles[file] !== title ? `${titles[file]} > ${title}` : title, id !== null ? "#" + id : "", @@ -308,46 +344,47 @@ const Search = { // search for explicit entries in index directives for (const [entry, foundEntries] of Object.entries(indexEntries)) { if (entry.includes(queryLower) && (queryLower.length >= entry.length/2)) { - for (const [file, id] of foundEntries) { - let score = Math.round(100 * queryLower.length / entry.length) - results.push([ + for (const [file, id, isMain] of foundEntries) { + const score = Math.round(100 * queryLower.length / entry.length); + const result = [ docNames[file], titles[file], id ? "#" + id : "", null, score, filenames[file], - ]); + ]; + if (isMain) { + normalResults.push(result); + } else { + nonMainIndexResults.push(result); + } } } } // lookup as object objectTerms.forEach((term) => - results.push(...Search.performObjectSearch(term, objectTerms)) + normalResults.push(...Search.performObjectSearch(term, objectTerms)) ); // lookup as search terms in fulltext - results.push(...Search.performTermsSearch(searchTerms, excludedTerms)); + normalResults.push(...Search.performTermsSearch(searchTerms, excludedTerms)); // let the scorer override scores with a custom scoring function - if (Scorer.score) results.forEach((item) => (item[4] = Scorer.score(item))); - - // now sort the results by score (in opposite order of appearance, since the - // display function below uses pop() to retrieve items) and then - // alphabetically - results.sort((a, b) => { - const leftScore = a[4]; - const rightScore = b[4]; - if (leftScore === rightScore) { - // same score: sort alphabetically - const leftTitle = a[1].toLowerCase(); - const rightTitle = b[1].toLowerCase(); - if (leftTitle === rightTitle) return 0; - return leftTitle > rightTitle ? -1 : 1; // inverted is intentional - } - return leftScore > rightScore ? 1 : -1; - }); + if (Scorer.score) { + normalResults.forEach((item) => (item[4] = Scorer.score(item))); + nonMainIndexResults.forEach((item) => (item[4] = Scorer.score(item))); + } + + // Sort each group of results by score and then alphabetically by name. + normalResults.sort(_orderResultsByScoreThenName); + nonMainIndexResults.sort(_orderResultsByScoreThenName); + + // Combine the result groups in (reverse) order. + // Non-main index entries are typically arbitrary cross-references, + // so display them after other results. + let results = [...nonMainIndexResults, ...normalResults]; // remove duplicate search results // note the reversing of results, so that in the case of duplicates, the highest-scoring entry is kept @@ -361,7 +398,12 @@ const Search = { return acc; }, []); - results = results.reverse(); + return results.reverse(); + }, + + query: (query) => { + const [searchQuery, searchTerms, excludedTerms, highlightTerms, objectTerms] = Search._parseQuery(query); + const results = Search._performSearch(searchQuery, searchTerms, excludedTerms, highlightTerms, objectTerms); // for debugging //Search.lastresults = results.slice(); // a copy @@ -466,14 +508,18 @@ const Search = { // add support for partial matches if (word.length > 2) { const escapedWord = _escapeRegExp(word); - Object.keys(terms).forEach((term) => { - if (term.match(escapedWord) && !terms[word]) - arr.push({ files: terms[term], score: Scorer.partialTerm }); - }); - Object.keys(titleTerms).forEach((term) => { - if (term.match(escapedWord) && !titleTerms[word]) - arr.push({ files: titleTerms[word], score: Scorer.partialTitle }); - }); + if (!terms.hasOwnProperty(word)) { + Object.keys(terms).forEach((term) => { + if (term.match(escapedWord)) + arr.push({ files: terms[term], score: Scorer.partialTerm }); + }); + } + if (!titleTerms.hasOwnProperty(word)) { + Object.keys(titleTerms).forEach((term) => { + if (term.match(escapedWord)) + arr.push({ files: titleTerms[term], score: Scorer.partialTitle }); + }); + } } // no match but word was a required one @@ -496,9 +542,8 @@ const Search = { // create the mapping files.forEach((file) => { - if (fileMap.has(file) && fileMap.get(file).indexOf(word) === -1) - fileMap.get(file).push(word); - else fileMap.set(file, [word]); + if (!fileMap.has(file)) fileMap.set(file, [word]); + else if (fileMap.get(file).indexOf(word) === -1) fileMap.get(file).push(word); }); }); @@ -549,8 +594,8 @@ const Search = { * search summary for a given text. keywords is a list * of stemmed words. */ - makeSearchSummary: (htmlText, keywords) => { - const text = Search.htmlToText(htmlText); + makeSearchSummary: (htmlText, keywords, anchor) => { + const text = Search.htmlToText(htmlText, anchor); if (text === "") return null; const textLower = text.toLowerCase(); diff --git a/latest/changelog.html b/latest/changelog.html index 05f4079..5961e02 100644 --- a/latest/changelog.html +++ b/latest/changelog.html @@ -14,7 +14,7 @@ - + Changelog - TorchCAM @@ -222,37 +222,37 @@
-

Changelog#

+

Changelog

-

v0.4.0 (2023-10-19)#

+

v0.4.0 (2023-10-19)

Release note: v0.4.0

-

v0.3.2 (2022-08-02)#

+

v0.3.2 (2022-08-02)

Release note: v0.3.2

-

v0.3.1 (2021-10-31)#

+

v0.3.1 (2021-10-31)

Release note: v0.3.1

-

v0.3.0 (2021-10-31)#

+

v0.3.0 (2021-10-31)

Release note: v0.3.0

-

v0.2.0 (2021-04-10)#

+

v0.2.0 (2021-04-10)

Release note: v0.2.0

-

v0.1.2 (2020-12-27)#

+

v0.1.2 (2020-12-27)

Release note: v0.1.2

-

v0.1.1 (2020-08-03)#

+

v0.1.1 (2020-08-03)

Release note: v0.1.1

-

v0.1.0 (2020-03-24)#

+

v0.1.0 (2020-03-24)

Release note: v0.1.0

@@ -332,7 +332,7 @@

v0.1.0 (2020-03-24) - + diff --git a/latest/genindex.html b/latest/genindex.html index 57bac9c..3af1c03 100644 --- a/latest/genindex.html +++ b/latest/genindex.html @@ -13,7 +13,7 @@ - Index - TorchCAM + Index - TorchCAM @@ -361,7 +361,7 @@

X

- + diff --git a/latest/index.html b/latest/index.html index 0c44303..37307c0 100644 --- a/latest/index.html +++ b/latest/index.html @@ -14,7 +14,7 @@ - + TorchCAM @@ -222,7 +222,7 @@
-

TorchCAM: class activation explorer#

+

TorchCAM: class activation explorer

TorchCAM provides a minimal yet flexible way to explore the spatial importance of features on your PyTorch model outputs. Check out the live demo on HuggingFace Spaces 🤗

code_snippet

This project is meant for:

@@ -233,9 +233,9 @@

TorchCAM: class activation explorer
-

CAM zoo#

+

CAM zoo

-

Activation-based methods#

+

Activation-based methods

- + + \ No newline at end of file diff --git a/latest/installing.html b/latest/installing.html index 2542696..351e234 100644 --- a/latest/installing.html +++ b/latest/installing.html @@ -14,7 +14,7 @@ - + Installation - TorchCAM @@ -222,24 +222,24 @@
-

Installation#

+

Installation

This library requires Python 3.8 or higher.

-

Via Python Package#

+

Via Python Package

Install the last stable release of the package using pip:

pip install torchcam
 
-

Via Conda#

+

Via Conda

Install the last stable release of the package using conda:

conda install -c frgfm torchcam
 
-

Via Git#

+

Via Git

Install the library in developer mode:

git clone https://github.com/frgfm/torch-cam.git
 pip install -e torch-cam/.
@@ -326,7 +326,7 @@ 

Via Git#<

- + diff --git a/latest/methods.html b/latest/methods.html index 0deb134..5b05eda 100644 --- a/latest/methods.html +++ b/latest/methods.html @@ -14,7 +14,7 @@ - + torchcam.methods - TorchCAM @@ -222,9 +222,9 @@
-

torchcam.methods#

+

torchcam.methods

-

Class activation map#

+

Class activation map

The class activation map gives you the importance of each region of a feature map on a model’s output. More specifically, a class activation map is relative to:

-

Activation-based methods#

+

Activation-based methods

Methods related to activation-based class activation maps.

-class torchcam.methods.CAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, fc_layer: Module | str | None = None, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]#
+class torchcam.methods.CAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, fc_layer: Module | str | None = None, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]

Implements a class activation map extractor as described in “Learning Deep Features for Discriminative Localization”.

The Class Activation Map (CAM) is defined for image classification models that have global pooling at the end @@ -274,7 +274,7 @@

Activation-based methods
-class torchcam.methods.ScoreCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, batch_size: int = 32, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]#
+class torchcam.methods.ScoreCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, batch_size: int = 32, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]

Implements a class activation map extractor as described in “Score-CAM: Score-Weighted Visual Explanations for Convolutional Neural Networks”.

The localization map is computed as follows:

@@ -319,7 +319,7 @@

Activation-based methods
-class torchcam.methods.SSCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, batch_size: int = 32, num_samples: int = 35, std: float = 2.0, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]#
+class torchcam.methods.SSCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, batch_size: int = 32, num_samples: int = 35, std: float = 2.0, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]

Implements a class activation map extractor as described in “SS-CAM: Smoothed Score-CAM for Sharper Visual Feature Localization”.

The localization map is computed as follows:

@@ -369,7 +369,7 @@

Activation-based methods
-class torchcam.methods.ISCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, batch_size: int = 32, num_samples: int = 10, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]#
+class torchcam.methods.ISCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, batch_size: int = 32, num_samples: int = 10, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]

Implements a class activation map extractor as described in “IS-CAM: Integrated Score-CAM for axiomatic-based explanations”.

The localization map is computed as follows:

@@ -417,11 +417,11 @@

Activation-based methods -

Gradient-based methods#

+

Gradient-based methods

Methods related to gradient-based class activation maps.

-class torchcam.methods.GradCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]#
+class torchcam.methods.GradCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]

Implements a class activation map extractor as described in “Grad-CAM: Visual Explanations from Deep Networks via Gradient-based Localization”.

The localization map is computed as follows:

@@ -459,7 +459,7 @@

Gradient-based methods
-class torchcam.methods.GradCAMpp(model: Module, target_layer: Module | str | List[Module | str] | None = None, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]#
+class torchcam.methods.GradCAMpp(model: Module, target_layer: Module | str | List[Module | str] | None = None, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]

Implements a class activation map extractor as described in “Grad-CAM++: Improved Visual Explanations for Deep Convolutional Networks”.

The localization map is computed as follows:

@@ -506,7 +506,7 @@

Gradient-based methods
-class torchcam.methods.SmoothGradCAMpp(model: Module, target_layer: Module | str | List[Module | str] | None = None, num_samples: int = 4, std: float = 0.3, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]#
+class torchcam.methods.SmoothGradCAMpp(model: Module, target_layer: Module | str | List[Module | str] | None = None, num_samples: int = 4, std: float = 0.3, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]

Implements a class activation map extractor as described in “Smooth Grad-CAM++: An Enhanced Inference Level Visualization Technique for Deep Convolutional Neural Network Models” with a personal correction to the paper (alpha coefficient numerator).

@@ -563,7 +563,7 @@

Gradient-based methods
-class torchcam.methods.XGradCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]#
+class torchcam.methods.XGradCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]

Implements a class activation map extractor as described in “Axiom-based Grad-CAM: Towards Accurate Visualization and Explanation of CNNs”.

The localization map is computed as follows:

@@ -602,7 +602,7 @@

Gradient-based methods
-class torchcam.methods.LayerCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]#
+class torchcam.methods.LayerCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]

Implements a class activation map extractor as described in “LayerCAM: Exploring Hierarchical Class Activation Maps for Localization”.

The localization map is computed as follows:

@@ -638,7 +638,7 @@

Gradient-based methods
-classmethod fuse_cams(cams: List[Tensor], target_shape: Tuple[int, int] | None = None) Tensor#
+classmethod fuse_cams(cams: List[Tensor], target_shape: Tuple[int, int] | None = None) Tensor

Fuse class activation maps from different layers.

Parameters:
@@ -756,7 +756,7 @@

Gradient-based methods - + diff --git a/latest/metrics.html b/latest/metrics.html index 6573d62..16fbe28 100644 --- a/latest/metrics.html +++ b/latest/metrics.html @@ -14,7 +14,7 @@ - + torchcam.metrics - TorchCAM @@ -222,11 +222,11 @@
-

torchcam.metrics#

+

torchcam.metrics

Apart from qualitative visual comparison, it is important to have a refined evaluation metric for class activation maps. This submodule is dedicated to the evaluation of CAM methods.

-class torchcam.metrics.ClassificationMetric(cam_extractor: _CAM, logits_fn: Callable[[Tensor], Tensor] | None = None)[source]#
+class torchcam.metrics.ClassificationMetric(cam_extractor: _CAM, logits_fn: Callable[[Tensor], Tensor] | None = None)[source]

Implements Average Drop and Increase in Confidence from “Grad-CAM++: Improved Visual Explanations for Deep Convolutional Networks.”.

The raw aggregated metric is computed as follows:

@@ -267,7 +267,7 @@

torchcam.metrics
-update(input_tensor: Tensor, class_idx: int | None = None) None[source]#
+update(input_tensor: Tensor, class_idx: int | None = None) None[source]

Update the state of the metric with new predictions

Parameters:
@@ -281,7 +281,7 @@

torchcam.metrics
-summary() Dict[str, float][source]#
+summary() Dict[str, float][source]

Computes the aggregated metrics

Returns:
@@ -374,7 +374,7 @@

torchcam.metrics - + diff --git a/latest/notebooks.html b/latest/notebooks.html index e13e6cb..2c1debb 100644 --- a/latest/notebooks.html +++ b/latest/notebooks.html @@ -14,7 +14,7 @@ - + TorchCAM Notebooks - TorchCAM @@ -222,7 +222,7 @@
-

TorchCAM Notebooks#

+

TorchCAM Notebooks

Here are some notebooks compiled for users to better leverage the library capabilities:

@@ -303,7 +303,7 @@

TorchCAM Notebooks - + diff --git a/latest/search.html b/latest/search.html index 2e55119..e9612db 100644 --- a/latest/search.html +++ b/latest/search.html @@ -13,7 +13,7 @@ - Search - TorchCAM + Search - TorchCAM @@ -260,7 +260,7 @@ - + diff --git a/latest/searchindex.js b/latest/searchindex.js index ca19d95..f2909be 100644 --- a/latest/searchindex.js +++ b/latest/searchindex.js @@ -1 +1 @@ -Search.setIndex({"docnames": ["changelog", "index", "installing", "methods", "metrics", "notebooks", "utils"], "filenames": ["changelog.rst", "index.rst", "installing.rst", "methods.rst", "metrics.rst", "notebooks.md", "utils.rst"], "titles": ["Changelog", "TorchCAM: class activation explorer", "Installation", "torchcam.methods", "torchcam.metrics", "TorchCAM Notebooks", "torchcam.utils"], "terms": {"releas": [0, 2], "note": [0, 3], "provid": 1, "minim": 1, "yet": 1, "flexibl": 1, "wai": 1, "spatial": [1, 3], "import": [1, 3, 4, 6], "featur": [1, 3, 5], "your": [1, 3], "pytorch": 1, "model": [1, 3, 4], "output": [1, 3], "check": 1, "out": [1, 3], "live": 1, "demo": 1, "huggingfac": 1, "space": 1, "thi": [1, 2, 4], "project": 1, "i": [1, 3, 4], "meant": 1, "easili": 1, "assess": 1, "influenc": 1, "": [1, 3], "research": 1, "quickli": 1, "implement": [1, 3, 4], "own": 1, "idea": 1, "new": [1, 4], "from": [1, 3, 4, 6], "learn": [1, 3], "deep": [1, 3, 4], "discrimin": [1, 3], "local": [1, 3], "score": [1, 3], "weight": [1, 3], "visual": [1, 3, 4], "explan": [1, 3, 4], "convolut": [1, 3, 4], "neural": [1, 3], "network": [1, 3, 4], "ss": [1, 3], "smooth": [1, 3], "sharper": [1, 3], "integr": [1, 3], "axiomat": [1, 3], "grad": [1, 3, 4], "via": [1, 3], "improv": [1, 3, 4], "an": [1, 3, 6], "enhanc": [1, 3], "infer": [1, 3], "level": [1, 3], "techniqu": [1, 3], "x": [1, 3, 4], "axiom": [1, 3], "toward": [1, 3], "accur": [1, 3], "cnn": [1, 3], "layer": [1, 3], "layercam": [1, 3], "hierarch": [1, 3], "map": [1, 4], "librari": [2, 5], "requir": 2, "3": [2, 3, 4], "8": 2, "higher": 2, "last": 2, "stabl": 2, "us": [2, 3], "pip": 2, "torchcam": 2, "c": [2, 3, 4], "frgfm": 2, "develop": 2, "mode": 2, "clone": 2, "http": 2, "github": 2, "com": 2, "torch": [2, 3, 4], "cam": [2, 3, 4, 5, 6], "e": [2, 3], "The": [3, 4], "give": 3, "you": 3, "each": [3, 4], "region": 3, "more": 3, "specif": 3, "rel": 3, "which": 3, "comput": [3, 4], "g": 3, "n": [3, 4], "th": 3, "classif": [3, 4], "raw": [3, 4], "logit": 3, "index": [3, 4], "focu": [3, 4], "With": 3, "target": 3, "select": 3, "when": [3, 6], "creat": 3, "extractor": 3, "need": 3, "pass": 3, "do": 3, "its": 3, "magic": 3, "relat": 3, "modul": 3, "target_lay": 3, "str": [3, 4, 6], "list": 3, "none": [3, 4], "fc_layer": 3, "input_shap": 3, "tupl": 3, "int": [3, 4], "224": 3, "kwarg": 3, "ani": 3, "sourc": [3, 4, 6], "describ": 3, "defin": [3, 4], "imag": [3, 6], "have": [3, 4, 6], "global": 3, "pool": 3, "end": [3, 4], "extract": 3, "block": 3, "follow": [3, 4], "l": 3, "_": 3, "y": 3, "relu": 3, "big": 3, "sum": [3, 4], "limits_k": 3, "w_k": 3, "a_k": 3, "where": [3, 4], "node": 3, "k": 3, "posit": 3, "correspond": 3, "unit": 3, "fulli": 3, "connect": 3, "torchvis": 3, "resnet18": 3, "pretrain": 3, "true": 3, "eval": 3, "layer4": 3, "fc": 3, "no_grad": 3, "input_tensor": [3, 4], "class_idx": [3, 4], "100": 3, "paramet": [3, 4, 6], "input": [3, 4], "either": 3, "itself": 3, "name": 3, "those": 3, "shape": 3, "expect": 3, "tensor": [3, 4], "exclud": 3, "batch": 3, "dimens": 3, "scorecam": 3, "batch_siz": 3, "32": 3, "coeffici": 3, "being": 3, "softmax": [3, 4], "m_k": 3, "x_b": 3, "_k": 3, "befor": 3, "baselin": 3, "frac": [3, 4], "u": 3, "min": 3, "limits_m": 3, "a_m": 3, "max": [3, 4], "odot": 3, "refer": 3, "element": 3, "wise": 3, "multipl": 3, "upsampl": 3, "oper": 3, "size": 3, "forward": 3, "mask": [3, 6], "sscam": 3, "num_sampl": 3, "35": 3, "std": 3, "float": [3, 4, 6], "2": 3, "0": [3, 4, 6], "1": [3, 4], "limits_": [3, 4], "hat": 3, "number": 3, "sampl": [3, 4], "bigg": 3, "delta": 3, "sim": 3, "mathcal": [3, 4], "sigma": 3, "random": 3, "nois": 3, "mean": 3, "gaussian": 3, "distribut": 3, "standard": 3, "deviat": 3, "noisi": 3, "ad": 3, "normal": 3, "iscam": 3, "10": 3, "iss": 3, "m_i": 3, "j": 3, "isscam": 3, "gradcam": 3, "h": [3, 4], "cdot": 3, "w": [3, 4], "partial": [3, 4], "gradcampp": 3, "alpha_k": 3, "b": 3, "els": 3, "smoothgradcampp": 3, "4": 3, "person": 3, "correct": 3, "paper": 3, "alpha": [3, 6], "numer": 3, "m": [3, 4], "d": 3, "here": [3, 5], "p": 3, "deriv": 3, "get": 3, "estim": 3, "pleas": 3, "differ": 3, "actual": 3, "xgradcam": 3, "xgrad": 3, "explor": 3, "fused_cam": 3, "fuse_cam": 3, "classmethod": 3, "target_shap": 3, "fuse": 3, "same": 3, "default": [3, 4], "biggest": 3, "among": 3, "return": [3, 4, 6], "type": [3, 6], "apart": 4, "qualit": 4, "comparison": 4, "refin": 4, "evalu": 4, "class": 4, "activ": 4, "submodul": 4, "dedic": 4, "method": [4, 5], "classificationmetr": 4, "cam_extractor": 4, "_cam": 4, "logits_fn": 4, "callabl": 4, "averag": 4, "drop": 4, "increas": 4, "confid": 4, "aggreg": 4, "foral": 4, "mathbb": 4, "r": 4, "avgdrop_": 4, "f_": 4, "x_i": 4, "incrconf_": 4, "g_": 4, "set": 4, "gener": 4, "function": 4, "e_": 4, "resiz": 4, "left": 4, "begin": 4, "arrai": 4, "ll": 4, "mbox": 4, "otherwis": 4, "right": 4, "functool": 4, "dim": 4, "updat": 4, "summari": 4, "state": 4, "predict": 4, "preprocess": 4, "top": 4, "dict": 4, "dictionari": 4, "ar": 5, "some": 5, "compil": 5, "user": 5, "better": 5, "leverag": 5, "capabl": 5, "descript": 5, "quicktour": 5, "A": 5, "present": 5, "main": 5, "latenc": 5, "benchmark": 5, "how": 5, "overlay_mask": 6, "img": 6, "colormap": 6, "jet": 6, "7": 6, "overlai": 6, "background": 6, "pil": 6, "matplotlib": 6, "pyplot": 6, "plt": 6, "grayscal": 6, "appli": 6, "transpar": 6, "rais": 6, "typeerror": 6, "argument": 6, "invalid": 6, "valueerror": 6, "ha": 6, "incorrect": 6, "valu": 6}, "objects": {"torchcam.methods": [[3, 0, 1, "", "CAM"], [3, 0, 1, "", "GradCAM"], [3, 0, 1, "", "GradCAMpp"], [3, 0, 1, "", "ISCAM"], [3, 0, 1, "", "LayerCAM"], [3, 0, 1, "", "SSCAM"], [3, 0, 1, "", "ScoreCAM"], [3, 0, 1, "", "SmoothGradCAMpp"], [3, 0, 1, "", "XGradCAM"]], "torchcam.methods.LayerCAM": [[3, 1, 1, "", "fuse_cams"]], "torchcam.metrics": [[4, 0, 1, "", "ClassificationMetric"]], "torchcam.metrics.ClassificationMetric": [[4, 1, 1, "", "summary"], [4, 1, 1, "", "update"]], "torchcam.utils": [[6, 2, 1, "", "overlay_mask"]]}, "objtypes": {"0": "py:class", "1": "py:method", "2": "py:function"}, "objnames": {"0": ["py", "class", "Python class"], "1": ["py", "method", "Python method"], "2": ["py", "function", "Python function"]}, "titleterms": {"changelog": 0, "v0": 0, "4": 0, "0": 0, "2023": 0, "10": 0, "19": 0, "3": 0, "2": 0, "2022": 0, "08": 0, "02": 0, "1": 0, "2021": 0, "31": 0, "04": 0, "2020": 0, "12": 0, "27": 0, "03": 0, "24": 0, "torchcam": [1, 3, 4, 5, 6], "class": [1, 3], "activ": [1, 3], "explor": 1, "cam": 1, "zoo": 1, "base": [1, 3], "method": [1, 3], "gradient": [1, 3], "instal": 2, "via": 2, "python": 2, "packag": 2, "conda": 2, "git": 2, "map": 3, "metric": 4, "notebook": 5, "util": 6}, "envversion": {"sphinx.domains.c": 3, "sphinx.domains.changeset": 1, "sphinx.domains.citation": 1, "sphinx.domains.cpp": 9, "sphinx.domains.index": 1, "sphinx.domains.javascript": 3, "sphinx.domains.math": 2, "sphinx.domains.python": 4, "sphinx.domains.rst": 2, "sphinx.domains.std": 2, "sphinx.ext.viewcode": 1, "sphinx": 60}, "alltitles": {"Changelog": [[0, "changelog"]], "v0.4.0 (2023-10-19)": [[0, "v0-4-0-2023-10-19"]], "v0.3.2 (2022-08-02)": [[0, "v0-3-2-2022-08-02"]], "v0.3.1 (2021-10-31)": [[0, "v0-3-1-2021-10-31"]], "v0.3.0 (2021-10-31)": [[0, "v0-3-0-2021-10-31"]], "v0.2.0 (2021-04-10)": [[0, "v0-2-0-2021-04-10"]], "v0.1.2 (2020-12-27)": [[0, "v0-1-2-2020-12-27"]], "v0.1.1 (2020-08-03)": [[0, "v0-1-1-2020-08-03"]], "v0.1.0 (2020-03-24)": [[0, "v0-1-0-2020-03-24"]], "TorchCAM: class activation explorer": [[1, "torchcam-class-activation-explorer"]], "CAM zoo": [[1, "cam-zoo"]], "Activation-based methods": [[1, "activation-based-methods"], [3, "activation-based-methods"]], "Gradient-based methods": [[1, "gradient-based-methods"], [3, "gradient-based-methods"]], "Installation": [[2, "installation"]], "Via Python Package": [[2, "via-python-package"]], "Via Conda": [[2, "via-conda"]], "Via Git": [[2, "via-git"]], "torchcam.methods": [[3, "torchcam-methods"]], "Class activation map": [[3, "class-activation-map"]], "torchcam.metrics": [[4, "torchcam-metrics"]], "TorchCAM Notebooks": [[5, "torchcam-notebooks"]], "torchcam.utils": [[6, "torchcam-utils"]]}, "indexentries": {"cam (class in torchcam.methods)": [[3, "torchcam.methods.CAM"]], "gradcam (class in torchcam.methods)": [[3, "torchcam.methods.GradCAM"]], "gradcampp (class in torchcam.methods)": [[3, "torchcam.methods.GradCAMpp"]], "iscam (class in torchcam.methods)": [[3, "torchcam.methods.ISCAM"]], "layercam (class in torchcam.methods)": [[3, "torchcam.methods.LayerCAM"]], "sscam (class in torchcam.methods)": [[3, "torchcam.methods.SSCAM"]], "scorecam (class in torchcam.methods)": [[3, "torchcam.methods.ScoreCAM"]], "smoothgradcampp (class in torchcam.methods)": [[3, "torchcam.methods.SmoothGradCAMpp"]], "xgradcam (class in torchcam.methods)": [[3, "torchcam.methods.XGradCAM"]], "fuse_cams() (torchcam.methods.layercam class method)": [[3, "torchcam.methods.LayerCAM.fuse_cams"]], "classificationmetric (class in torchcam.metrics)": [[4, "torchcam.metrics.ClassificationMetric"]], "summary() (torchcam.metrics.classificationmetric method)": [[4, "torchcam.metrics.ClassificationMetric.summary"]], "update() (torchcam.metrics.classificationmetric method)": [[4, "torchcam.metrics.ClassificationMetric.update"]], "overlay_mask() (in module torchcam.utils)": [[6, "torchcam.utils.overlay_mask"]]}}) \ No newline at end of file +Search.setIndex({"alltitles": {"Activation-based methods": [[1, "activation-based-methods"], [3, "activation-based-methods"]], "CAM zoo": [[1, "cam-zoo"]], "Changelog": [[0, "changelog"]], "Class activation map": [[3, "class-activation-map"]], "Gradient-based methods": [[1, "gradient-based-methods"], [3, "gradient-based-methods"]], "Installation": [[2, "installation"]], "TorchCAM Notebooks": [[5, "torchcam-notebooks"]], "TorchCAM: class activation explorer": [[1, "torchcam-class-activation-explorer"]], "Via Conda": [[2, "via-conda"]], "Via Git": [[2, "via-git"]], "Via Python Package": [[2, "via-python-package"]], "torchcam.methods": [[3, "torchcam-methods"]], "torchcam.metrics": [[4, "torchcam-metrics"]], "torchcam.utils": [[6, "torchcam-utils"]], "v0.1.0 (2020-03-24)": [[0, "v0-1-0-2020-03-24"]], "v0.1.1 (2020-08-03)": [[0, "v0-1-1-2020-08-03"]], "v0.1.2 (2020-12-27)": [[0, "v0-1-2-2020-12-27"]], "v0.2.0 (2021-04-10)": [[0, "v0-2-0-2021-04-10"]], "v0.3.0 (2021-10-31)": [[0, "v0-3-0-2021-10-31"]], "v0.3.1 (2021-10-31)": [[0, "v0-3-1-2021-10-31"]], "v0.3.2 (2022-08-02)": [[0, "v0-3-2-2022-08-02"]], "v0.4.0 (2023-10-19)": [[0, "v0-4-0-2023-10-19"]]}, "docnames": ["changelog", "index", "installing", "methods", "metrics", "notebooks", "utils"], "envversion": {"sphinx": 61, "sphinx.domains.c": 3, "sphinx.domains.changeset": 1, "sphinx.domains.citation": 1, "sphinx.domains.cpp": 9, "sphinx.domains.index": 1, "sphinx.domains.javascript": 3, "sphinx.domains.math": 2, "sphinx.domains.python": 4, "sphinx.domains.rst": 2, "sphinx.domains.std": 2, "sphinx.ext.viewcode": 1}, "filenames": ["changelog.rst", "index.rst", "installing.rst", "methods.rst", "metrics.rst", "notebooks.md", "utils.rst"], "indexentries": {"cam (class in torchcam.methods)": [[3, "torchcam.methods.CAM", false]], "classificationmetric (class in torchcam.metrics)": [[4, "torchcam.metrics.ClassificationMetric", false]], "fuse_cams() (torchcam.methods.layercam class method)": [[3, "torchcam.methods.LayerCAM.fuse_cams", false]], "gradcam (class in torchcam.methods)": [[3, "torchcam.methods.GradCAM", false]], "gradcampp (class in torchcam.methods)": [[3, "torchcam.methods.GradCAMpp", false]], "iscam (class in torchcam.methods)": [[3, "torchcam.methods.ISCAM", false]], "layercam (class in torchcam.methods)": [[3, "torchcam.methods.LayerCAM", false]], "overlay_mask() (in module torchcam.utils)": [[6, "torchcam.utils.overlay_mask", false]], "scorecam (class in torchcam.methods)": [[3, "torchcam.methods.ScoreCAM", false]], "smoothgradcampp (class in torchcam.methods)": [[3, "torchcam.methods.SmoothGradCAMpp", false]], "sscam (class in torchcam.methods)": [[3, "torchcam.methods.SSCAM", false]], "summary() (torchcam.metrics.classificationmetric method)": [[4, "torchcam.metrics.ClassificationMetric.summary", false]], "update() (torchcam.metrics.classificationmetric method)": [[4, "torchcam.metrics.ClassificationMetric.update", false]], "xgradcam (class in torchcam.methods)": [[3, "torchcam.methods.XGradCAM", false]]}, "objects": {"torchcam.methods": [[3, 0, 1, "", "CAM"], [3, 0, 1, "", "GradCAM"], [3, 0, 1, "", "GradCAMpp"], [3, 0, 1, "", "ISCAM"], [3, 0, 1, "", "LayerCAM"], [3, 0, 1, "", "SSCAM"], [3, 0, 1, "", "ScoreCAM"], [3, 0, 1, "", "SmoothGradCAMpp"], [3, 0, 1, "", "XGradCAM"]], "torchcam.methods.LayerCAM": [[3, 1, 1, "", "fuse_cams"]], "torchcam.metrics": [[4, 0, 1, "", "ClassificationMetric"]], "torchcam.metrics.ClassificationMetric": [[4, 1, 1, "", "summary"], [4, 1, 1, "", "update"]], "torchcam.utils": [[6, 2, 1, "", "overlay_mask"]]}, "objnames": {"0": ["py", "class", "Python class"], "1": ["py", "method", "Python method"], "2": ["py", "function", "Python function"]}, "objtypes": {"0": "py:class", "1": "py:method", "2": "py:function"}, "terms": {"": [1, 3], "0": [3, 4, 6], "1": [3, 4], "10": 3, "100": 3, "2": 3, "224": 3, "3": [2, 3, 4], "32": 3, "35": 3, "4": 3, "7": 6, "8": 2, "A": 5, "The": [3, 4], "With": 3, "_": 3, "_cam": 4, "_k": 3, "a_k": 3, "a_m": 3, "accur": [1, 3], "activ": 4, "actual": 3, "ad": 3, "aggreg": 4, "alpha": [3, 6], "alpha_k": 3, "among": 3, "an": [1, 3, 6], "ani": 3, "apart": 4, "appli": 6, "ar": 5, "argument": 6, "arrai": 4, "assess": 1, "averag": 4, "avgdrop_": 4, "axiom": [1, 3], "axiomat": [1, 3], "b": 3, "background": 6, "baselin": 3, "batch": 3, "batch_siz": 3, "befor": 3, "begin": 4, "being": 3, "benchmark": 5, "better": 5, "big": 3, "bigg": 3, "biggest": 3, "block": 3, "c": [2, 3, 4], "callabl": 4, "cam": [2, 3, 4, 5, 6], "cam_extractor": 4, "capabl": 5, "cdot": 3, "check": 1, "class": 4, "class_idx": [3, 4], "classif": [3, 4], "classificationmetr": 4, "classmethod": 3, "clone": 2, "cnn": [1, 3], "coeffici": 3, "colormap": 6, "com": 2, "comparison": 4, "compil": 5, "comput": [3, 4], "confid": 4, "connect": 3, "convolut": [1, 3, 4], "correct": 3, "correspond": 3, "creat": 3, "d": 3, "dedic": 4, "deep": [1, 3, 4], "default": [3, 4], "defin": [3, 4], "delta": 3, "demo": 1, "deriv": 3, "describ": 3, "descript": 5, "develop": 2, "deviat": 3, "dict": 4, "dictionari": 4, "differ": 3, "dim": 4, "dimens": 3, "discrimin": [1, 3], "distribut": 3, "do": 3, "drop": 4, "e": [2, 3], "e_": 4, "each": [3, 4], "easili": 1, "either": 3, "element": 3, "els": 3, "end": [3, 4], "enhanc": [1, 3], "estim": 3, "eval": 3, "evalu": 4, "exclud": 3, "expect": 3, "explan": [1, 3, 4], "explor": 3, "extract": 3, "extractor": 3, "f_": 4, "fc": 3, "fc_layer": 3, "featur": [1, 3, 5], "flexibl": 1, "float": [3, 4, 6], "focu": [3, 4], "follow": [3, 4], "foral": 4, "forward": 3, "frac": [3, 4], "frgfm": 2, "from": [1, 3, 4, 6], "fulli": 3, "function": 4, "functool": 4, "fuse": 3, "fuse_cam": 3, "fused_cam": 3, "g": 3, "g_": 4, "gaussian": 3, "gener": 4, "get": 3, "github": 2, "give": 3, "global": 3, "grad": [1, 3, 4], "gradcam": 3, "gradcampp": 3, "grayscal": 6, "h": [3, 4], "ha": 6, "hat": 3, "have": [3, 4, 6], "here": [3, 5], "hierarch": [1, 3], "higher": 2, "how": 5, "http": 2, "huggingfac": 1, "i": [1, 3, 4], "idea": 1, "imag": [3, 6], "img": 6, "implement": [1, 3, 4], "import": [1, 3, 4, 6], "improv": [1, 3, 4], "incorrect": 6, "incrconf_": 4, "increas": 4, "index": [3, 4], "infer": [1, 3], "influenc": 1, "input": [3, 4], "input_shap": 3, "input_tensor": [3, 4], "int": [3, 4], "integr": [1, 3], "invalid": 6, "iscam": 3, "iss": 3, "isscam": 3, "its": 3, "itself": 3, "j": 3, "jet": 6, "k": 3, "kwarg": 3, "l": 3, "last": 2, "latenc": 5, "layer": [1, 3], "layer4": 3, "layercam": [1, 3], "learn": [1, 3], "left": 4, "level": [1, 3], "leverag": 5, "librari": [2, 5], "limits_": [3, 4], "limits_k": 3, "limits_m": 3, "list": 3, "live": 1, "ll": 4, "local": [1, 3], "logit": 3, "logits_fn": 4, "m": [3, 4], "m_i": 3, "m_k": 3, "magic": 3, "main": 5, "map": [1, 4], "mask": [3, 6], "mathbb": 4, "mathcal": [3, 4], "matplotlib": 6, "max": [3, 4], "mbox": 4, "mean": 3, "meant": 1, "method": [4, 5], "min": 3, "minim": 1, "mode": 2, "model": [1, 3, 4], "modul": 3, "more": 3, "multipl": 3, "n": [3, 4], "name": 3, "need": 3, "network": [1, 3, 4], "neural": [1, 3], "new": [1, 4], "no_grad": 3, "node": 3, "nois": 3, "noisi": 3, "none": [3, 4], "normal": 3, "note": [0, 3], "num_sampl": 3, "number": 3, "numer": 3, "odot": 3, "oper": 3, "otherwis": 4, "out": [1, 3], "output": [1, 3], "overlai": 6, "overlay_mask": 6, "own": 1, "p": 3, "paper": 3, "paramet": [3, 4, 6], "partial": [3, 4], "pass": 3, "person": 3, "pil": 6, "pip": 2, "pleas": 3, "plt": 6, "pool": 3, "posit": 3, "predict": 4, "preprocess": 4, "present": 5, "pretrain": 3, "project": 1, "provid": 1, "pyplot": 6, "pytorch": 1, "qualit": 4, "quickli": 1, "quicktour": 5, "r": 4, "rais": 6, "random": 3, "raw": [3, 4], "refer": 3, "refin": 4, "region": 3, "rel": 3, "relat": 3, "releas": [0, 2], "relu": 3, "requir": 2, "research": 1, "resiz": 4, "resnet18": 3, "return": [3, 4, 6], "right": 4, "same": 3, "sampl": [3, 4], "score": [1, 3], "scorecam": 3, "select": 3, "set": 4, "shape": 3, "sharper": [1, 3], "sigma": 3, "sim": 3, "size": 3, "smooth": [1, 3], "smoothgradcampp": 3, "softmax": [3, 4], "some": 5, "sourc": [3, 4, 6], "space": 1, "spatial": [1, 3], "specif": 3, "ss": [1, 3], "sscam": 3, "stabl": 2, "standard": 3, "state": 4, "std": 3, "str": [3, 4, 6], "submodul": 4, "sum": [3, 4], "summari": 4, "target": 3, "target_lay": 3, "target_shap": 3, "techniqu": [1, 3], "tensor": [3, 4], "th": 3, "thi": [1, 2, 4], "those": 3, "top": 4, "torch": [2, 3, 4], "torchcam": 2, "torchvis": 3, "toward": [1, 3], "transpar": 6, "true": 3, "tupl": 3, "type": [3, 6], "typeerror": 6, "u": 3, "unit": 3, "updat": 4, "upsampl": 3, "us": [2, 3], "user": 5, "valu": 6, "valueerror": 6, "via": [1, 3], "visual": [1, 3, 4], "w": [3, 4], "w_k": 3, "wai": 1, "weight": [1, 3], "when": [3, 6], "where": [3, 4], "which": 3, "wise": 3, "x": [1, 3, 4], "x_b": 3, "x_i": 4, "xgrad": 3, "xgradcam": 3, "y": 3, "yet": 1, "you": 3, "your": [1, 3]}, "titles": ["Changelog", "TorchCAM: class activation explorer", "Installation", "torchcam.methods", "torchcam.metrics", "TorchCAM Notebooks", "torchcam.utils"], "titleterms": {"0": 0, "02": 0, "03": 0, "04": 0, "08": 0, "1": 0, "10": 0, "12": 0, "19": 0, "2": 0, "2020": 0, "2021": 0, "2022": 0, "2023": 0, "24": 0, "27": 0, "3": 0, "31": 0, "4": 0, "activ": [1, 3], "base": [1, 3], "cam": 1, "changelog": 0, "class": [1, 3], "conda": 2, "explor": 1, "git": 2, "gradient": [1, 3], "instal": 2, "map": 3, "method": [1, 3], "metric": 4, "notebook": 5, "packag": 2, "python": 2, "torchcam": [1, 3, 4, 5, 6], "util": 6, "v0": 0, "via": 2, "zoo": 1}}) \ No newline at end of file diff --git a/latest/utils.html b/latest/utils.html index 884e9d4..d200e4a 100644 --- a/latest/utils.html +++ b/latest/utils.html @@ -14,7 +14,7 @@ - + torchcam.utils - TorchCAM @@ -222,10 +222,10 @@
-

torchcam.utils#

+

torchcam.utils

-torchcam.utils.overlay_mask(img: Image, mask: Image, colormap: str = 'jet', alpha: float = 0.7) Image[source]#
+torchcam.utils.overlay_mask(img: Image, mask: Image, colormap: str = 'jet', alpha: float = 0.7) Image[source]

Overlay a colormapped mask on a background image

-

torchcam.methods#

+

torchcam.methods

-

Class activation map#

+

Class activation map

The class activation map gives you the importance of each region of a feature map on a model’s output. More specifically, a class activation map is relative to:

-

Activation-based methods#

+

Activation-based methods

Methods related to activation-based class activation maps.

-class torchcam.methods.CAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, fc_layer: Module | str | None = None, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]#
+class torchcam.methods.CAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, fc_layer: Module | str | None = None, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]

Implements a class activation map extractor as described in “Learning Deep Features for Discriminative Localization”.

The Class Activation Map (CAM) is defined for image classification models that have global pooling at the end @@ -274,7 +274,7 @@

Activation-based methods
-class torchcam.methods.ScoreCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, batch_size: int = 32, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]#
+class torchcam.methods.ScoreCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, batch_size: int = 32, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]

Implements a class activation map extractor as described in “Score-CAM: Score-Weighted Visual Explanations for Convolutional Neural Networks”.

The localization map is computed as follows:

@@ -319,7 +319,7 @@

Activation-based methods
-class torchcam.methods.SSCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, batch_size: int = 32, num_samples: int = 35, std: float = 2.0, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]#
+class torchcam.methods.SSCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, batch_size: int = 32, num_samples: int = 35, std: float = 2.0, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]

Implements a class activation map extractor as described in “SS-CAM: Smoothed Score-CAM for Sharper Visual Feature Localization”.

The localization map is computed as follows:

@@ -369,7 +369,7 @@

Activation-based methods
-class torchcam.methods.ISCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, batch_size: int = 32, num_samples: int = 10, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]#
+class torchcam.methods.ISCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, batch_size: int = 32, num_samples: int = 10, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]

Implements a class activation map extractor as described in “IS-CAM: Integrated Score-CAM for axiomatic-based explanations”.

The localization map is computed as follows:

@@ -417,11 +417,11 @@

Activation-based methods -

Gradient-based methods#

+

Gradient-based methods

Methods related to gradient-based class activation maps.

-class torchcam.methods.GradCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]#
+class torchcam.methods.GradCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]

Implements a class activation map extractor as described in “Grad-CAM: Visual Explanations from Deep Networks via Gradient-based Localization”.

The localization map is computed as follows:

@@ -459,7 +459,7 @@

Gradient-based methods
-class torchcam.methods.GradCAMpp(model: Module, target_layer: Module | str | List[Module | str] | None = None, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]#
+class torchcam.methods.GradCAMpp(model: Module, target_layer: Module | str | List[Module | str] | None = None, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]

Implements a class activation map extractor as described in “Grad-CAM++: Improved Visual Explanations for Deep Convolutional Networks”.

The localization map is computed as follows:

@@ -506,7 +506,7 @@

Gradient-based methods
-class torchcam.methods.SmoothGradCAMpp(model: Module, target_layer: Module | str | List[Module | str] | None = None, num_samples: int = 4, std: float = 0.3, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]#
+class torchcam.methods.SmoothGradCAMpp(model: Module, target_layer: Module | str | List[Module | str] | None = None, num_samples: int = 4, std: float = 0.3, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]

Implements a class activation map extractor as described in “Smooth Grad-CAM++: An Enhanced Inference Level Visualization Technique for Deep Convolutional Neural Network Models” with a personal correction to the paper (alpha coefficient numerator).

@@ -563,7 +563,7 @@

Gradient-based methods
-class torchcam.methods.XGradCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]#
+class torchcam.methods.XGradCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]

Implements a class activation map extractor as described in “Axiom-based Grad-CAM: Towards Accurate Visualization and Explanation of CNNs”.

The localization map is computed as follows:

@@ -602,7 +602,7 @@

Gradient-based methods
-class torchcam.methods.LayerCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]#
+class torchcam.methods.LayerCAM(model: Module, target_layer: Module | str | List[Module | str] | None = None, input_shape: Tuple[int, ...] = (3, 224, 224), **kwargs: Any)[source]

Implements a class activation map extractor as described in “LayerCAM: Exploring Hierarchical Class Activation Maps for Localization”.

The localization map is computed as follows:

@@ -638,7 +638,7 @@

Gradient-based methods
-classmethod fuse_cams(cams: List[Tensor], target_shape: Tuple[int, int] | None = None) Tensor#
+classmethod fuse_cams(cams: List[Tensor], target_shape: Tuple[int, int] | None = None) Tensor

Fuse class activation maps from different layers.

Parameters:
@@ -756,7 +756,7 @@

Gradient-based methods

- + diff --git a/metrics.html b/metrics.html index 823ed70..ca4a7d1 100644 --- a/metrics.html +++ b/metrics.html @@ -14,7 +14,7 @@ - + torchcam.metrics - TorchCAM @@ -222,11 +222,11 @@
-

torchcam.metrics#

+

torchcam.metrics

Apart from qualitative visual comparison, it is important to have a refined evaluation metric for class activation maps. This submodule is dedicated to the evaluation of CAM methods.

-class torchcam.metrics.ClassificationMetric(cam_extractor: _CAM, logits_fn: Callable[[Tensor], Tensor] | None = None)[source]#
+class torchcam.metrics.ClassificationMetric(cam_extractor: _CAM, logits_fn: Callable[[Tensor], Tensor] | None = None)[source]

Implements Average Drop and Increase in Confidence from “Grad-CAM++: Improved Visual Explanations for Deep Convolutional Networks.”.

The raw aggregated metric is computed as follows:

@@ -267,7 +267,7 @@

torchcam.metrics
-update(input_tensor: Tensor, class_idx: int | None = None) None[source]#
+update(input_tensor: Tensor, class_idx: int | None = None) None[source]

Update the state of the metric with new predictions

Parameters:
@@ -281,7 +281,7 @@

torchcam.metrics
-summary() Dict[str, float][source]#
+summary() Dict[str, float][source]

Computes the aggregated metrics

Returns:
@@ -374,7 +374,7 @@

torchcam.metrics - + diff --git a/notebooks.html b/notebooks.html index 2963401..38be093 100644 --- a/notebooks.html +++ b/notebooks.html @@ -14,7 +14,7 @@ - + TorchCAM Notebooks - TorchCAM @@ -222,7 +222,7 @@
-

TorchCAM Notebooks#

+

TorchCAM Notebooks

Here are some notebooks compiled for users to better leverage the library capabilities:

@@ -303,7 +303,7 @@

TorchCAM Notebooks - + diff --git a/search.html b/search.html index 4f4886c..2cfde52 100644 --- a/search.html +++ b/search.html @@ -13,7 +13,7 @@ - Search - TorchCAM + Search - TorchCAM @@ -260,7 +260,7 @@ - + diff --git a/searchindex.js b/searchindex.js index 8fba5fe..28af11a 100644 --- a/searchindex.js +++ b/searchindex.js @@ -1 +1 @@ -Search.setIndex({"docnames": ["changelog", "index", "installing", "methods", "metrics", "notebooks", "utils"], "filenames": ["changelog.rst", "index.rst", "installing.rst", "methods.rst", "metrics.rst", "notebooks.md", "utils.rst"], "titles": ["Changelog", "TorchCAM: class activation explorer", "Installation", "torchcam.methods", "torchcam.metrics", "TorchCAM Notebooks", "torchcam.utils"], "terms": {"releas": [0, 2], "note": [0, 3], "provid": 1, "minim": 1, "yet": 1, "flexibl": 1, "wai": 1, "spatial": [1, 3], "import": [1, 3, 4, 6], "featur": [1, 3, 5], "your": [1, 3], "pytorch": 1, "model": [1, 3, 4], "output": [1, 3], "check": 1, "out": [1, 3], "live": 1, "demo": 1, "huggingfac": 1, "space": 1, "thi": [1, 2, 4], "project": 1, "i": [1, 3, 4], "meant": 1, "easili": 1, "assess": 1, "influenc": 1, "": [1, 3], "research": 1, "quickli": 1, "implement": [1, 3, 4], "own": 1, "idea": 1, "new": [1, 4], "from": [1, 3, 4, 6], "learn": [1, 3], "deep": [1, 3, 4], "discrimin": [1, 3], "local": [1, 3], "score": [1, 3], "weight": [1, 3], "visual": [1, 3, 4], "explan": [1, 3, 4], "convolut": [1, 3, 4], "neural": [1, 3], "network": [1, 3, 4], "ss": [1, 3], "smooth": [1, 3], "sharper": [1, 3], "integr": [1, 3], "axiomat": [1, 3], "grad": [1, 3, 4], "via": [1, 3], "improv": [1, 3, 4], "an": [1, 3, 6], "enhanc": [1, 3], "infer": [1, 3], "level": [1, 3], "techniqu": [1, 3], "x": [1, 3, 4], "axiom": [1, 3], "toward": [1, 3], "accur": [1, 3], "cnn": [1, 3], "layer": [1, 3], "layercam": [1, 3], "hierarch": [1, 3], "map": [1, 4], "librari": [2, 5], "requir": 2, "3": [2, 3, 4], "8": 2, "higher": 2, "last": 2, "stabl": 2, "us": [2, 3], "pip": 2, "torchcam": 2, "c": [2, 3, 4], "frgfm": 2, "develop": 2, "mode": 2, "clone": 2, "http": 2, "github": 2, "com": 2, "torch": [2, 3, 4], "cam": [2, 3, 4, 5, 6], "e": [2, 3], "The": [3, 4], "give": 3, "you": 3, "each": [3, 4], "region": 3, "more": 3, "specif": 3, "rel": 3, "which": 3, "comput": [3, 4], "g": 3, "n": [3, 4], "th": 3, "classif": [3, 4], "raw": [3, 4], "logit": 3, "index": [3, 4], "focu": [3, 4], "With": 3, "target": 3, "select": 3, "when": [3, 6], "creat": 3, "extractor": 3, "need": 3, "pass": 3, "do": 3, "its": 3, "magic": 3, "relat": 3, "modul": 3, "target_lay": 3, "str": [3, 4, 6], "list": 3, "none": [3, 4], "fc_layer": 3, "input_shap": 3, "tupl": 3, "int": [3, 4], "224": 3, "kwarg": 3, "ani": 3, "sourc": [3, 4, 6], "describ": 3, "defin": [3, 4], "imag": [3, 6], "have": [3, 4, 6], "global": 3, "pool": 3, "end": [3, 4], "extract": 3, "block": 3, "follow": [3, 4], "l": 3, "_": 3, "y": 3, "relu": 3, "big": 3, "sum": [3, 4], "limits_k": 3, "w_k": 3, "a_k": 3, "where": [3, 4], "node": 3, "k": 3, "posit": 3, "correspond": 3, "unit": 3, "fulli": 3, "connect": 3, "torchvis": 3, "resnet18": 3, "pretrain": 3, "true": 3, "eval": 3, "layer4": 3, "fc": 3, "no_grad": 3, "input_tensor": [3, 4], "class_idx": [3, 4], "100": 3, "paramet": [3, 4, 6], "input": [3, 4], "either": 3, "itself": 3, "name": 3, "those": 3, "shape": 3, "expect": 3, "tensor": [3, 4], "exclud": 3, "batch": 3, "dimens": 3, "scorecam": 3, "batch_siz": 3, "32": 3, "coeffici": 3, "being": 3, "softmax": [3, 4], "m_k": 3, "x_b": 3, "_k": 3, "befor": 3, "baselin": 3, "frac": [3, 4], "u": 3, "min": 3, "limits_m": 3, "a_m": 3, "max": [3, 4], "odot": 3, "refer": 3, "element": 3, "wise": 3, "multipl": 3, "upsampl": 3, "oper": 3, "size": 3, "forward": 3, "mask": [3, 6], "sscam": 3, "num_sampl": 3, "35": 3, "std": 3, "float": [3, 4, 6], "2": 3, "0": [3, 4, 6], "1": [3, 4], "limits_": [3, 4], "hat": 3, "number": 3, "sampl": [3, 4], "bigg": 3, "delta": 3, "sim": 3, "mathcal": [3, 4], "sigma": 3, "random": 3, "nois": 3, "mean": 3, "gaussian": 3, "distribut": 3, "standard": 3, "deviat": 3, "noisi": 3, "ad": 3, "normal": 3, "iscam": 3, "10": 3, "iss": 3, "m_i": 3, "j": 3, "isscam": 3, "gradcam": 3, "h": [3, 4], "cdot": 3, "w": [3, 4], "partial": [3, 4], "gradcampp": 3, "alpha_k": 3, "b": 3, "els": 3, "smoothgradcampp": 3, "4": 3, "person": 3, "correct": 3, "paper": 3, "alpha": [3, 6], "numer": 3, "m": [3, 4], "d": 3, "here": [3, 5], "p": 3, "deriv": 3, "get": 3, "estim": 3, "pleas": 3, "differ": 3, "actual": 3, "xgradcam": 3, "xgrad": 3, "explor": 3, "fused_cam": 3, "fuse_cam": 3, "classmethod": 3, "target_shap": 3, "fuse": 3, "same": 3, "default": [3, 4], "biggest": 3, "among": 3, "return": [3, 4, 6], "type": [3, 6], "apart": 4, "qualit": 4, "comparison": 4, "refin": 4, "evalu": 4, "class": 4, "activ": 4, "submodul": 4, "dedic": 4, "method": [4, 5], "classificationmetr": 4, "cam_extractor": 4, "_cam": 4, "logits_fn": 4, "callabl": 4, "averag": 4, "drop": 4, "increas": 4, "confid": 4, "aggreg": 4, "foral": 4, "mathbb": 4, "r": 4, "avgdrop_": 4, "f_": 4, "x_i": 4, "incrconf_": 4, "g_": 4, "set": 4, "gener": 4, "function": 4, "e_": 4, "resiz": 4, "left": 4, "begin": 4, "arrai": 4, "ll": 4, "mbox": 4, "otherwis": 4, "right": 4, "functool": 4, "dim": 4, "updat": 4, "summari": 4, "state": 4, "predict": 4, "preprocess": 4, "top": 4, "dict": 4, "dictionari": 4, "ar": 5, "some": 5, "compil": 5, "user": 5, "better": 5, "leverag": 5, "capabl": 5, "descript": 5, "quicktour": 5, "A": 5, "present": 5, "main": 5, "latenc": 5, "benchmark": 5, "how": 5, "overlay_mask": 6, "img": 6, "colormap": 6, "jet": 6, "7": 6, "overlai": 6, "background": 6, "pil": 6, "matplotlib": 6, "pyplot": 6, "plt": 6, "grayscal": 6, "appli": 6, "transpar": 6, "rais": 6, "typeerror": 6, "argument": 6, "invalid": 6, "valueerror": 6, "ha": 6, "incorrect": 6, "valu": 6}, "objects": {"torchcam.methods": [[3, 0, 1, "", "CAM"], [3, 0, 1, "", "GradCAM"], [3, 0, 1, "", "GradCAMpp"], [3, 0, 1, "", "ISCAM"], [3, 0, 1, "", "LayerCAM"], [3, 0, 1, "", "SSCAM"], [3, 0, 1, "", "ScoreCAM"], [3, 0, 1, "", "SmoothGradCAMpp"], [3, 0, 1, "", "XGradCAM"]], "torchcam.methods.LayerCAM": [[3, 1, 1, "", "fuse_cams"]], "torchcam.metrics": [[4, 0, 1, "", "ClassificationMetric"]], "torchcam.metrics.ClassificationMetric": [[4, 1, 1, "", "summary"], [4, 1, 1, "", "update"]], "torchcam.utils": [[6, 2, 1, "", "overlay_mask"]]}, "objtypes": {"0": "py:class", "1": "py:method", "2": "py:function"}, "objnames": {"0": ["py", "class", "Python class"], "1": ["py", "method", "Python method"], "2": ["py", "function", "Python function"]}, "titleterms": {"changelog": 0, "v0": 0, "3": 0, "2": 0, "2022": 0, "08": 0, "02": 0, "1": 0, "2021": 0, "10": 0, "31": 0, "0": 0, "04": 0, "2020": 0, "12": 0, "27": 0, "03": 0, "24": 0, "torchcam": [1, 3, 4, 5, 6], "class": [1, 3], "activ": [1, 3], "explor": 1, "cam": 1, "zoo": 1, "base": [1, 3], "method": [1, 3], "gradient": [1, 3], "instal": 2, "via": 2, "python": 2, "packag": 2, "conda": 2, "git": 2, "map": 3, "metric": 4, "notebook": 5, "util": 6}, "envversion": {"sphinx.domains.c": 3, "sphinx.domains.changeset": 1, "sphinx.domains.citation": 1, "sphinx.domains.cpp": 9, "sphinx.domains.index": 1, "sphinx.domains.javascript": 3, "sphinx.domains.math": 2, "sphinx.domains.python": 4, "sphinx.domains.rst": 2, "sphinx.domains.std": 2, "sphinx.ext.viewcode": 1, "sphinx": 60}, "alltitles": {"Changelog": [[0, "changelog"]], "v0.3.2 (2022-08-02)": [[0, "v0-3-2-2022-08-02"]], "v0.3.1 (2021-10-31)": [[0, "v0-3-1-2021-10-31"]], "v0.3.0 (2021-10-31)": [[0, "v0-3-0-2021-10-31"]], "v0.2.0 (2021-04-10)": [[0, "v0-2-0-2021-04-10"]], "v0.1.2 (2020-12-27)": [[0, "v0-1-2-2020-12-27"]], "v0.1.1 (2020-08-03)": [[0, "v0-1-1-2020-08-03"]], "v0.1.0 (2020-03-24)": [[0, "v0-1-0-2020-03-24"]], "TorchCAM: class activation explorer": [[1, "torchcam-class-activation-explorer"]], "CAM zoo": [[1, "cam-zoo"]], "Activation-based methods": [[1, "activation-based-methods"], [3, "activation-based-methods"]], "Gradient-based methods": [[1, "gradient-based-methods"], [3, "gradient-based-methods"]], "Installation": [[2, "installation"]], "Via Python Package": [[2, "via-python-package"]], "Via Conda": [[2, "via-conda"]], "Via Git": [[2, "via-git"]], "torchcam.methods": [[3, "torchcam-methods"]], "Class activation map": [[3, "class-activation-map"]], "torchcam.metrics": [[4, "torchcam-metrics"]], "TorchCAM Notebooks": [[5, "torchcam-notebooks"]], "torchcam.utils": [[6, "torchcam-utils"]]}, "indexentries": {"cam (class in torchcam.methods)": [[3, "torchcam.methods.CAM"]], "gradcam (class in torchcam.methods)": [[3, "torchcam.methods.GradCAM"]], "gradcampp (class in torchcam.methods)": [[3, "torchcam.methods.GradCAMpp"]], "iscam (class in torchcam.methods)": [[3, "torchcam.methods.ISCAM"]], "layercam (class in torchcam.methods)": [[3, "torchcam.methods.LayerCAM"]], "sscam (class in torchcam.methods)": [[3, "torchcam.methods.SSCAM"]], "scorecam (class in torchcam.methods)": [[3, "torchcam.methods.ScoreCAM"]], "smoothgradcampp (class in torchcam.methods)": [[3, "torchcam.methods.SmoothGradCAMpp"]], "xgradcam (class in torchcam.methods)": [[3, "torchcam.methods.XGradCAM"]], "fuse_cams() (torchcam.methods.layercam class method)": [[3, "torchcam.methods.LayerCAM.fuse_cams"]], "classificationmetric (class in torchcam.metrics)": [[4, "torchcam.metrics.ClassificationMetric"]], "summary() (torchcam.metrics.classificationmetric method)": [[4, "torchcam.metrics.ClassificationMetric.summary"]], "update() (torchcam.metrics.classificationmetric method)": [[4, "torchcam.metrics.ClassificationMetric.update"]], "overlay_mask() (in module torchcam.utils)": [[6, "torchcam.utils.overlay_mask"]]}}) \ No newline at end of file +Search.setIndex({"alltitles": {"Activation-based methods": [[1, "activation-based-methods"], [3, "activation-based-methods"]], "CAM zoo": [[1, "cam-zoo"]], "Changelog": [[0, "changelog"]], "Class activation map": [[3, "class-activation-map"]], "Gradient-based methods": [[1, "gradient-based-methods"], [3, "gradient-based-methods"]], "Installation": [[2, "installation"]], "TorchCAM Notebooks": [[5, "torchcam-notebooks"]], "TorchCAM: class activation explorer": [[1, "torchcam-class-activation-explorer"]], "Via Conda": [[2, "via-conda"]], "Via Git": [[2, "via-git"]], "Via Python Package": [[2, "via-python-package"]], "torchcam.methods": [[3, "torchcam-methods"]], "torchcam.metrics": [[4, "torchcam-metrics"]], "torchcam.utils": [[6, "torchcam-utils"]], "v0.1.0 (2020-03-24)": [[0, "v0-1-0-2020-03-24"]], "v0.1.1 (2020-08-03)": [[0, "v0-1-1-2020-08-03"]], "v0.1.2 (2020-12-27)": [[0, "v0-1-2-2020-12-27"]], "v0.2.0 (2021-04-10)": [[0, "v0-2-0-2021-04-10"]], "v0.3.0 (2021-10-31)": [[0, "v0-3-0-2021-10-31"]], "v0.3.1 (2021-10-31)": [[0, "v0-3-1-2021-10-31"]], "v0.3.2 (2022-08-02)": [[0, "v0-3-2-2022-08-02"]]}, "docnames": ["changelog", "index", "installing", "methods", "metrics", "notebooks", "utils"], "envversion": {"sphinx": 61, "sphinx.domains.c": 3, "sphinx.domains.changeset": 1, "sphinx.domains.citation": 1, "sphinx.domains.cpp": 9, "sphinx.domains.index": 1, "sphinx.domains.javascript": 3, "sphinx.domains.math": 2, "sphinx.domains.python": 4, "sphinx.domains.rst": 2, "sphinx.domains.std": 2, "sphinx.ext.viewcode": 1}, "filenames": ["changelog.rst", "index.rst", "installing.rst", "methods.rst", "metrics.rst", "notebooks.md", "utils.rst"], "indexentries": {"cam (class in torchcam.methods)": [[3, "torchcam.methods.CAM", false]], "classificationmetric (class in torchcam.metrics)": [[4, "torchcam.metrics.ClassificationMetric", false]], "fuse_cams() (torchcam.methods.layercam class method)": [[3, "torchcam.methods.LayerCAM.fuse_cams", false]], "gradcam (class in torchcam.methods)": [[3, "torchcam.methods.GradCAM", false]], "gradcampp (class in torchcam.methods)": [[3, "torchcam.methods.GradCAMpp", false]], "iscam (class in torchcam.methods)": [[3, "torchcam.methods.ISCAM", false]], "layercam (class in torchcam.methods)": [[3, "torchcam.methods.LayerCAM", false]], "overlay_mask() (in module torchcam.utils)": [[6, "torchcam.utils.overlay_mask", false]], "scorecam (class in torchcam.methods)": [[3, "torchcam.methods.ScoreCAM", false]], "smoothgradcampp (class in torchcam.methods)": [[3, "torchcam.methods.SmoothGradCAMpp", false]], "sscam (class in torchcam.methods)": [[3, "torchcam.methods.SSCAM", false]], "summary() (torchcam.metrics.classificationmetric method)": [[4, "torchcam.metrics.ClassificationMetric.summary", false]], "update() (torchcam.metrics.classificationmetric method)": [[4, "torchcam.metrics.ClassificationMetric.update", false]], "xgradcam (class in torchcam.methods)": [[3, "torchcam.methods.XGradCAM", false]]}, "objects": {"torchcam.methods": [[3, 0, 1, "", "CAM"], [3, 0, 1, "", "GradCAM"], [3, 0, 1, "", "GradCAMpp"], [3, 0, 1, "", "ISCAM"], [3, 0, 1, "", "LayerCAM"], [3, 0, 1, "", "SSCAM"], [3, 0, 1, "", "ScoreCAM"], [3, 0, 1, "", "SmoothGradCAMpp"], [3, 0, 1, "", "XGradCAM"]], "torchcam.methods.LayerCAM": [[3, 1, 1, "", "fuse_cams"]], "torchcam.metrics": [[4, 0, 1, "", "ClassificationMetric"]], "torchcam.metrics.ClassificationMetric": [[4, 1, 1, "", "summary"], [4, 1, 1, "", "update"]], "torchcam.utils": [[6, 2, 1, "", "overlay_mask"]]}, "objnames": {"0": ["py", "class", "Python class"], "1": ["py", "method", "Python method"], "2": ["py", "function", "Python function"]}, "objtypes": {"0": "py:class", "1": "py:method", "2": "py:function"}, "terms": {"": [1, 3], "0": [3, 4, 6], "1": [3, 4], "10": 3, "100": 3, "2": 3, "224": 3, "3": [2, 3, 4], "32": 3, "35": 3, "4": 3, "7": 6, "8": 2, "A": 5, "The": [3, 4], "With": 3, "_": 3, "_cam": 4, "_k": 3, "a_k": 3, "a_m": 3, "accur": [1, 3], "activ": 4, "actual": 3, "ad": 3, "aggreg": 4, "alpha": [3, 6], "alpha_k": 3, "among": 3, "an": [1, 3, 6], "ani": 3, "apart": 4, "appli": 6, "ar": 5, "argument": 6, "arrai": 4, "assess": 1, "averag": 4, "avgdrop_": 4, "axiom": [1, 3], "axiomat": [1, 3], "b": 3, "background": 6, "baselin": 3, "batch": 3, "batch_siz": 3, "befor": 3, "begin": 4, "being": 3, "benchmark": 5, "better": 5, "big": 3, "bigg": 3, "biggest": 3, "block": 3, "c": [2, 3, 4], "callabl": 4, "cam": [2, 3, 4, 5, 6], "cam_extractor": 4, "capabl": 5, "cdot": 3, "check": 1, "class": 4, "class_idx": [3, 4], "classif": [3, 4], "classificationmetr": 4, "classmethod": 3, "clone": 2, "cnn": [1, 3], "coeffici": 3, "colormap": 6, "com": 2, "comparison": 4, "compil": 5, "comput": [3, 4], "confid": 4, "connect": 3, "convolut": [1, 3, 4], "correct": 3, "correspond": 3, "creat": 3, "d": 3, "dedic": 4, "deep": [1, 3, 4], "default": [3, 4], "defin": [3, 4], "delta": 3, "demo": 1, "deriv": 3, "describ": 3, "descript": 5, "develop": 2, "deviat": 3, "dict": 4, "dictionari": 4, "differ": 3, "dim": 4, "dimens": 3, "discrimin": [1, 3], "distribut": 3, "do": 3, "drop": 4, "e": [2, 3], "e_": 4, "each": [3, 4], "easili": 1, "either": 3, "element": 3, "els": 3, "end": [3, 4], "enhanc": [1, 3], "estim": 3, "eval": 3, "evalu": 4, "exclud": 3, "expect": 3, "explan": [1, 3, 4], "explor": 3, "extract": 3, "extractor": 3, "f_": 4, "fc": 3, "fc_layer": 3, "featur": [1, 3, 5], "flexibl": 1, "float": [3, 4, 6], "focu": [3, 4], "follow": [3, 4], "foral": 4, "forward": 3, "frac": [3, 4], "frgfm": 2, "from": [1, 3, 4, 6], "fulli": 3, "function": 4, "functool": 4, "fuse": 3, "fuse_cam": 3, "fused_cam": 3, "g": 3, "g_": 4, "gaussian": 3, "gener": 4, "get": 3, "github": 2, "give": 3, "global": 3, "grad": [1, 3, 4], "gradcam": 3, "gradcampp": 3, "grayscal": 6, "h": [3, 4], "ha": 6, "hat": 3, "have": [3, 4, 6], "here": [3, 5], "hierarch": [1, 3], "higher": 2, "how": 5, "http": 2, "huggingfac": 1, "i": [1, 3, 4], "idea": 1, "imag": [3, 6], "img": 6, "implement": [1, 3, 4], "import": [1, 3, 4, 6], "improv": [1, 3, 4], "incorrect": 6, "incrconf_": 4, "increas": 4, "index": [3, 4], "infer": [1, 3], "influenc": 1, "input": [3, 4], "input_shap": 3, "input_tensor": [3, 4], "int": [3, 4], "integr": [1, 3], "invalid": 6, "iscam": 3, "iss": 3, "isscam": 3, "its": 3, "itself": 3, "j": 3, "jet": 6, "k": 3, "kwarg": 3, "l": 3, "last": 2, "latenc": 5, "layer": [1, 3], "layer4": 3, "layercam": [1, 3], "learn": [1, 3], "left": 4, "level": [1, 3], "leverag": 5, "librari": [2, 5], "limits_": [3, 4], "limits_k": 3, "limits_m": 3, "list": 3, "live": 1, "ll": 4, "local": [1, 3], "logit": 3, "logits_fn": 4, "m": [3, 4], "m_i": 3, "m_k": 3, "magic": 3, "main": 5, "map": [1, 4], "mask": [3, 6], "mathbb": 4, "mathcal": [3, 4], "matplotlib": 6, "max": [3, 4], "mbox": 4, "mean": 3, "meant": 1, "method": [4, 5], "min": 3, "minim": 1, "mode": 2, "model": [1, 3, 4], "modul": 3, "more": 3, "multipl": 3, "n": [3, 4], "name": 3, "need": 3, "network": [1, 3, 4], "neural": [1, 3], "new": [1, 4], "no_grad": 3, "node": 3, "nois": 3, "noisi": 3, "none": [3, 4], "normal": 3, "note": [0, 3], "num_sampl": 3, "number": 3, "numer": 3, "odot": 3, "oper": 3, "otherwis": 4, "out": [1, 3], "output": [1, 3], "overlai": 6, "overlay_mask": 6, "own": 1, "p": 3, "paper": 3, "paramet": [3, 4, 6], "partial": [3, 4], "pass": 3, "person": 3, "pil": 6, "pip": 2, "pleas": 3, "plt": 6, "pool": 3, "posit": 3, "predict": 4, "preprocess": 4, "present": 5, "pretrain": 3, "project": 1, "provid": 1, "pyplot": 6, "pytorch": 1, "qualit": 4, "quickli": 1, "quicktour": 5, "r": 4, "rais": 6, "random": 3, "raw": [3, 4], "refer": 3, "refin": 4, "region": 3, "rel": 3, "relat": 3, "releas": [0, 2], "relu": 3, "requir": 2, "research": 1, "resiz": 4, "resnet18": 3, "return": [3, 4, 6], "right": 4, "same": 3, "sampl": [3, 4], "score": [1, 3], "scorecam": 3, "select": 3, "set": 4, "shape": 3, "sharper": [1, 3], "sigma": 3, "sim": 3, "size": 3, "smooth": [1, 3], "smoothgradcampp": 3, "softmax": [3, 4], "some": 5, "sourc": [3, 4, 6], "space": 1, "spatial": [1, 3], "specif": 3, "ss": [1, 3], "sscam": 3, "stabl": 2, "standard": 3, "state": 4, "std": 3, "str": [3, 4, 6], "submodul": 4, "sum": [3, 4], "summari": 4, "target": 3, "target_lay": 3, "target_shap": 3, "techniqu": [1, 3], "tensor": [3, 4], "th": 3, "thi": [1, 2, 4], "those": 3, "top": 4, "torch": [2, 3, 4], "torchcam": 2, "torchvis": 3, "toward": [1, 3], "transpar": 6, "true": 3, "tupl": 3, "type": [3, 6], "typeerror": 6, "u": 3, "unit": 3, "updat": 4, "upsampl": 3, "us": [2, 3], "user": 5, "valu": 6, "valueerror": 6, "via": [1, 3], "visual": [1, 3, 4], "w": [3, 4], "w_k": 3, "wai": 1, "weight": [1, 3], "when": [3, 6], "where": [3, 4], "which": 3, "wise": 3, "x": [1, 3, 4], "x_b": 3, "x_i": 4, "xgrad": 3, "xgradcam": 3, "y": 3, "yet": 1, "you": 3, "your": [1, 3]}, "titles": ["Changelog", "TorchCAM: class activation explorer", "Installation", "torchcam.methods", "torchcam.metrics", "TorchCAM Notebooks", "torchcam.utils"], "titleterms": {"0": 0, "02": 0, "03": 0, "04": 0, "08": 0, "1": 0, "10": 0, "12": 0, "2": 0, "2020": 0, "2021": 0, "2022": 0, "24": 0, "27": 0, "3": 0, "31": 0, "activ": [1, 3], "base": [1, 3], "cam": 1, "changelog": 0, "class": [1, 3], "conda": 2, "explor": 1, "git": 2, "gradient": [1, 3], "instal": 2, "map": 3, "method": [1, 3], "metric": 4, "notebook": 5, "packag": 2, "python": 2, "torchcam": [1, 3, 4, 5, 6], "util": 6, "v0": 0, "via": 2, "zoo": 1}}) \ No newline at end of file diff --git a/utils.html b/utils.html index dda927f..562781d 100644 --- a/utils.html +++ b/utils.html @@ -14,7 +14,7 @@ - + torchcam.utils - TorchCAM @@ -222,10 +222,10 @@
-

torchcam.utils#

+

torchcam.utils

-torchcam.utils.overlay_mask(img: Image, mask: Image, colormap: str = 'jet', alpha: float = 0.7) Image[source]#
+torchcam.utils.overlay_mask(img: Image, mask: Image, colormap: str = 'jet', alpha: float = 0.7) Image[source]

Overlay a colormapped mask on a background image

>>> from PIL import Image
 >>> import matplotlib.pyplot as plt
@@ -334,7 +334,7 @@ 

torchcam.utils - +