Skip to content

Commit e34fc42

Browse files
authored
docs: Fixed LaTeX syntax in docstrings (#107)
1 parent 5f510c3 commit e34fc42

File tree

2 files changed

+52
-52
lines changed

2 files changed

+52
-52
lines changed

torchcam/methods/activation.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CAM(_CAM):
2525
of the visual feature extraction block. The localization map is computed as follows:
2626
2727
.. math::
28-
L^{(c)}_{CAM}(x, y) = ReLU\\Big(\\sum\\limits_k w_k^{(c)} A_k(x, y)\\Big)
28+
L^{(c)}_{CAM}(x, y) = ReLU\Big(\sum\limits_k w_k^{(c)} A_k(x, y)\Big)
2929
3030
where :math:`A_k(x, y)` is the activation of node :math:`k` in the target layer of the model at
3131
position :math:`(x, y)`,
@@ -96,7 +96,7 @@ class ScoreCAM(_CAM):
9696
The localization map is computed as follows:
9797
9898
.. math::
99-
L^{(c)}_{Score-CAM}(x, y) = ReLU\\Big(\\sum\\limits_k w_k^{(c)} A_k(x, y)\\Big)
99+
L^{(c)}_{Score-CAM}(x, y) = ReLU\Big(\sum\limits_k w_k^{(c)} A_k(x, y)\Big)
100100
101101
with the coefficient :math:`w_k^{(c)}` being defined as:
102102
@@ -109,10 +109,10 @@ class ScoreCAM(_CAM):
109109
and :math:`M_k` is defined as follows:
110110
111111
.. math::
112-
M_k = \\frac{U(A_k) - \\min\\limits_m U(A_m)}{\\max\\limits_m U(A_m) - \\min\\limits_m U(A_m)})
113-
\\odot X
112+
M_k = \frac{U(A_k) - \min\limits_m U(A_m)}{\max\limits_m U(A_m) - \min\limits_m U(A_m)})
113+
\odot X
114114
115-
where :math:`\\odot` refers to the element-wise multiplication and :math:`U` is the upsampling operation.
115+
where :math:`\odot` refers to the element-wise multiplication and :math:`U` is the upsampling operation.
116116
117117
Example::
118118
>>> from torchvision.models import resnet18
@@ -216,12 +216,12 @@ class SSCAM(ScoreCAM):
216216
The localization map is computed as follows:
217217
218218
.. math::
219-
L^{(c)}_{SS-CAM}(x, y) = ReLU\\Big(\\sum\\limits_k w_k^{(c)} A_k(x, y)\\Big)
219+
L^{(c)}_{SS-CAM}(x, y) = ReLU\Big(\sum\limits_k w_k^{(c)} A_k(x, y)\Big)
220220
221221
with the coefficient :math:`w_k^{(c)}` being defined as:
222222
223223
.. math::
224-
w_k^{(c)} = \\frac{1}{N} \\sum\\limits_1^N softmax(Y^{(c)}(M_k) - Y^{(c)}(X_b))
224+
w_k^{(c)} = \frac{1}{N} \sum\limits_1^N softmax(Y^{(c)}(M_k) - Y^{(c)}(X_b))
225225
226226
where :math:`N` is the number of samples used to smooth the weights,
227227
:math:`A_k(x, y)` is the activation of node :math:`k` in the target layer of the model at
@@ -230,12 +230,12 @@ class SSCAM(ScoreCAM):
230230
and :math:`M_k` is defined as follows:
231231
232232
.. math::
233-
M_k = \\Bigg(\\frac{U(A_k) - \\min\\limits_m U(A_m)}{\\max\\limits_m U(A_m) - \\min\\limits_m U(A_m)} +
234-
\\delta\\Bigg) \\odot X
233+
M_k = \Bigg(\frac{U(A_k) - \min\limits_m U(A_m)}{\max\limits_m U(A_m) - \min\limits_m U(A_m)} +
234+
\delta\Bigg) \odot X
235235
236-
where :math:`\\odot` refers to the element-wise multiplication, :math:`U` is the upsampling operation,
237-
:math:`\\delta \\sim \\mathcal{N}(0, \\sigma^2)` is the random noise that follows a 0-mean gaussian distribution
238-
with a standard deviation of :math:`\\sigma`.
236+
where :math:`\odot` refers to the element-wise multiplication, :math:`U` is the upsampling operation,
237+
:math:`\delta \sim \mathcal{N}(0, \sigma^2)` is the random noise that follows a 0-mean gaussian distribution
238+
with a standard deviation of :math:`\sigma`.
239239
240240
Example::
241241
>>> from torchvision.models import resnet18
@@ -306,12 +306,12 @@ class ISCAM(ScoreCAM):
306306
The localization map is computed as follows:
307307
308308
.. math::
309-
L^{(c)}_{ISS-CAM}(x, y) = ReLU\\Big(\\sum\\limits_k w_k^{(c)} A_k(x, y)\\Big)
309+
L^{(c)}_{ISS-CAM}(x, y) = ReLU\Big(\sum\limits_k w_k^{(c)} A_k(x, y)\Big)
310310
311311
with the coefficient :math:`w_k^{(c)}` being defined as:
312312
313313
.. math::
314-
w_k^{(c)} = \\sum\\limits_{i=1}^N \\frac{i}{N} softmax(Y^{(c)}(M_k) - Y^{(c)}(X_b))
314+
w_k^{(c)} = \sum\limits_{i=1}^N \frac{i}{N} softmax(Y^{(c)}(M_k) - Y^{(c)}(X_b))
315315
316316
where :math:`N` is the number of samples used to smooth the weights,
317317
:math:`A_k(x, y)` is the activation of node :math:`k` in the target layer of the model at
@@ -320,12 +320,12 @@ class ISCAM(ScoreCAM):
320320
and :math:`M_k` is defined as follows:
321321
322322
.. math::
323-
M_k = \\Bigg(\\frac{U(A_k) - \\min\\limits_m U(A_m)}{\\max\\limits_m U(A_m) - \\min\\limits_m U(A_m)} +
324-
\\delta\\Bigg) \\odot X
323+
M_k = \Bigg(\frac{U(A_k) - \min\limits_m U(A_m)}{\max\limits_m U(A_m) - \min\limits_m U(A_m)} +
324+
\delta\Bigg) \odot X
325325
326-
where :math:`\\odot` refers to the element-wise multiplication, :math:`U` is the upsampling operation,
327-
:math:`\\delta \\sim \\mathcal{N}(0, \\sigma^2)` is the random noise that follows a 0-mean gaussian distribution
328-
with a standard deviation of :math:`\\sigma`.
326+
where :math:`\odot` refers to the element-wise multiplication, :math:`U` is the upsampling operation,
327+
:math:`\delta \sim \mathcal{N}(0, \sigma^2)` is the random noise that follows a 0-mean gaussian distribution
328+
with a standard deviation of :math:`\sigma`.
329329
330330
Example::
331331
>>> from torchvision.models import resnet18

torchcam/methods/gradient.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ class GradCAM(_GradCAM):
7272
The localization map is computed as follows:
7373
7474
.. math::
75-
L^{(c)}_{Grad-CAM}(x, y) = ReLU\\Big(\\sum\\limits_k w_k^{(c)} A_k(x, y)\\Big)
75+
L^{(c)}_{Grad-CAM}(x, y) = ReLU\Big(\sum\limits_k w_k^{(c)} A_k(x, y)\Big)
7676
7777
with the coefficient :math:`w_k^{(c)}` being defined as:
7878
7979
.. math::
80-
w_k^{(c)} = \\frac{1}{H \\cdot W} \\sum\\limits_{i=1}^H \\sum\\limits_{j=1}^W
81-
\\frac{\\partial Y^{(c)}}{\\partial A_k(i, j)}
80+
w_k^{(c)} = \frac{1}{H \cdot W} \sum\limits_{i=1}^H \sum\limits_{j=1}^W
81+
\frac{\partial Y^{(c)}}{\partial A_k(i, j)}
8282
8383
where :math:`A_k(x, y)` is the activation of node :math:`k` in the target layer of the model at
8484
position :math:`(x, y)`,
@@ -114,26 +114,26 @@ class GradCAMpp(_GradCAM):
114114
The localization map is computed as follows:
115115
116116
.. math::
117-
L^{(c)}_{Grad-CAM++}(x, y) = \\sum\\limits_k w_k^{(c)} A_k(x, y)
117+
L^{(c)}_{Grad-CAM++}(x, y) = \sum\limits_k w_k^{(c)} A_k(x, y)
118118
119119
with the coefficient :math:`w_k^{(c)}` being defined as:
120120
121121
.. math::
122-
w_k^{(c)} = \\sum\\limits_{i=1}^H \\sum\\limits_{j=1}^W \\alpha_k^{(c)}(i, j) \\cdot
123-
ReLU\\Big(\\frac{\\partial Y^{(c)}}{\\partial A_k(i, j)}\\Big)
122+
w_k^{(c)} = \sum\limits_{i=1}^H \sum\limits_{j=1}^W \alpha_k^{(c)}(i, j) \cdot
123+
ReLU\Big(\frac{\partial Y^{(c)}}{\partial A_k(i, j)}\Big)
124124
125125
where :math:`A_k(x, y)` is the activation of node :math:`k` in the target layer of the model at
126126
position :math:`(x, y)`,
127127
:math:`Y^{(c)}` is the model output score for class :math:`c` before softmax,
128-
and :math:`\\alpha_k^{(c)}(i, j)` being defined as:
128+
and :math:`\alpha_k^{(c)}(i, j)` being defined as:
129129
130130
.. math::
131-
\\alpha_k^{(c)}(i, j) = \\frac{1}{\\sum\\limits_{i, j} \\frac{\\partial Y^{(c)}}{\\partial A_k(i, j)}}
132-
= \\frac{\\frac{\\partial^2 Y^{(c)}}{(\\partial A_k(i,j))^2}}{2 \\cdot
133-
\\frac{\\partial^2 Y^{(c)}}{(\\partial A_k(i,j))^2} + \\sum\\limits_{a,b} A_k (a,b) \\cdot
134-
\\frac{\\partial^3 Y^{(c)}}{(\\partial A_k(i,j))^3}}
131+
\alpha_k^{(c)}(i, j) = \frac{1}{\sum\limits_{i, j} \frac{\partial Y^{(c)}}{\partial A_k(i, j)}}
132+
= \frac{\frac{\partial^2 Y^{(c)}}{(\partial A_k(i,j))^2}}{2 \cdot
133+
\frac{\partial^2 Y^{(c)}}{(\partial A_k(i,j))^2} + \sum\limits_{a,b} A_k (a,b) \cdot
134+
\frac{\partial^3 Y^{(c)}}{(\partial A_k(i,j))^3}}
135135
136-
if :math:`\\frac{\\partial Y^{(c)}}{\\partial A_k(i, j)} = 1` else :math:`0`.
136+
if :math:`\frac{\partial Y^{(c)}}{\partial A_k(i, j)} = 1` else :math:`0`.
137137
138138
Example::
139139
>>> from torchvision.models import resnet18
@@ -183,34 +183,34 @@ class SmoothGradCAMpp(_GradCAM):
183183
The localization map is computed as follows:
184184
185185
.. math::
186-
L^{(c)}_{Smooth Grad-CAM++}(x, y) = \\sum\\limits_k w_k^{(c)} A_k(x, y)
186+
L^{(c)}_{Smooth Grad-CAM++}(x, y) = \sum\limits_k w_k^{(c)} A_k(x, y)
187187
188188
with the coefficient :math:`w_k^{(c)}` being defined as:
189189
190190
.. math::
191-
w_k^{(c)} = \\sum\\limits_{i=1}^H \\sum\\limits_{j=1}^W \\alpha_k^{(c)}(i, j) \\cdot
192-
ReLU\\Big(\\frac{\\partial Y^{(c)}}{\\partial A_k(i, j)}\\Big)
191+
w_k^{(c)} = \sum\limits_{i=1}^H \sum\limits_{j=1}^W \alpha_k^{(c)}(i, j) \cdot
192+
ReLU\Big(\frac{\partial Y^{(c)}}{\partial A_k(i, j)}\Big)
193193
194194
where :math:`A_k(x, y)` is the activation of node :math:`k` in the target layer of the model at
195195
position :math:`(x, y)`,
196196
:math:`Y^{(c)}` is the model output score for class :math:`c` before softmax,
197-
and :math:`\\alpha_k^{(c)}(i, j)` being defined as:
197+
and :math:`\alpha_k^{(c)}(i, j)` being defined as:
198198
199199
.. math::
200-
\\alpha_k^{(c)}(i, j)
201-
= \\frac{\\frac{\\partial^2 Y^{(c)}}{(\\partial A_k(i,j))^2}}{2 \\cdot
202-
\\frac{\\partial^2 Y^{(c)}}{(\\partial A_k(i,j))^2} + \\sum\\limits_{a,b} A_k (a,b) \\cdot
203-
\\frac{\\partial^3 Y^{(c)}}{(\\partial A_k(i,j))^3}}
204-
= \\frac{\\frac{1}{n} \\sum\\limits_{m=1}^n D^{(c, 2)}_k(i, j)}{
205-
\\frac{2}{n} \\sum\\limits_{m=1}^n D^{(c, 2)}_k(i, j) + \\sum\\limits_{a,b} A_k (a,b) \\cdot
206-
\\frac{1}{n} \\sum\\limits_{m=1}^n D^{(c, 3)}_k(i, j)}
207-
208-
if :math:`\\frac{\\partial Y^{(c)}}{\\partial A_k(i, j)} = 1` else :math:`0`. Here :math:`D^{(c, p)}_k(i, j)`
200+
\alpha_k^{(c)}(i, j)
201+
= \frac{\frac{\partial^2 Y^{(c)}}{(\partial A_k(i,j))^2}}{2 \cdot
202+
\frac{\partial^2 Y^{(c)}}{(\partial A_k(i,j))^2} + \sum\limits_{a,b} A_k (a,b) \cdot
203+
\frac{\partial^3 Y^{(c)}}{(\partial A_k(i,j))^3}}
204+
= \frac{\frac{1}{n} \sum\limits_{m=1}^n D^{(c, 2)}_k(i, j)}{
205+
\frac{2}{n} \sum\limits_{m=1}^n D^{(c, 2)}_k(i, j) + \sum\limits_{a,b} A_k (a,b) \cdot
206+
\frac{1}{n} \sum\limits_{m=1}^n D^{(c, 3)}_k(i, j)}
207+
208+
if :math:`\frac{\partial Y^{(c)}}{\partial A_k(i, j)} = 1` else :math:`0`. Here :math:`D^{(c, p)}_k(i, j)`
209209
refers to the p-th partial derivative of the class score of class :math:`c` relatively to the activation in layer
210210
:math:`k` at position :math:`(i, j)`, and :math:`n` is the number of samples used to get the gradient estimate.
211211
212-
Please note the difference in the numerator of :math:`\\alpha_k^{(c)}(i, j)`,
213-
which is actually :math:`\\frac{1}{n} \\sum\\limits_{k=1}^n D^{(c, 1)}_k(i,j)` in the paper.
212+
Please note the difference in the numerator of :math:`\alpha_k^{(c)}(i, j)`,
213+
which is actually :math:`\frac{1}{n} \sum\limits_{k=1}^n D^{(c, 1)}_k(i,j)` in the paper.
214214
215215
Example::
216216
>>> from torchvision.models import resnet18
@@ -311,14 +311,14 @@ class XGradCAM(_GradCAM):
311311
The localization map is computed as follows:
312312
313313
.. math::
314-
L^{(c)}_{XGrad-CAM}(x, y) = ReLU\\Big(\\sum\\limits_k w_k^{(c)} A_k(x, y)\\Big)
314+
L^{(c)}_{XGrad-CAM}(x, y) = ReLU\Big(\sum\limits_k w_k^{(c)} A_k(x, y)\Big)
315315
316316
with the coefficient :math:`w_k^{(c)}` being defined as:
317317
318318
.. math::
319-
w_k^{(c)} = \\sum\\limits_{i=1}^H \\sum\\limits_{j=1}^W
320-
\\Big( \\frac{\\partial Y^{(c)}}{\\partial A_k(i, j)} \\cdot
321-
\\frac{A_k(i, j)}{\\sum\\limits_{m=1}^H \\sum\\limits_{n=1}^W A_k(m, n)} \\Big)
319+
w_k^{(c)} = \sum\limits_{i=1}^H \sum\limits_{j=1}^W
320+
\Big( \frac{\partial Y^{(c)}}{\partial A_k(i, j)} \cdot
321+
\frac{A_k(i, j)}{\sum\limits_{m=1}^H \sum\limits_{n=1}^W A_k(m, n)} \Big)
322322
323323
where :math:`A_k(x, y)` is the activation of node :math:`k` in the target layer of the model at
324324
position :math:`(x, y)`,
@@ -357,12 +357,12 @@ class LayerCAM(_GradCAM):
357357
The localization map is computed as follows:
358358
359359
.. math::
360-
L^{(c)}_{Layer-CAM}(x, y) = ReLU\\Big(\\sum\\limits_k w_k^{(c)}(x, y) \\cdot A_k(x, y)\\Big)
360+
L^{(c)}_{Layer-CAM}(x, y) = ReLU\Big(\sum\limits_k w_k^{(c)}(x, y) \cdot A_k(x, y)\Big)
361361
362362
with the coefficient :math:`w_k^{(c)}(x, y)` being defined as:
363363
364364
.. math::
365-
w_k^{(c)}(x, y) = ReLU\\Big(\\frac{\\partial Y^{(c)}}{\\partial A_k(i, j)}(x, y)\\Big)
365+
w_k^{(c)}(x, y) = ReLU\Big(\frac{\partial Y^{(c)}}{\partial A_k(i, j)}(x, y)\Big)
366366
367367
where :math:`A_k(x, y)` is the activation of node :math:`k` in the target layer of the model at
368368
position :math:`(x, y)`,

0 commit comments

Comments
 (0)