Skip to content

Commit 929a641

Browse files
author
pradeep
committed
Improve convolution batch support documentation
Also includes the following changes * Fix reference warnings in ml header * Improve conv docs in general
1 parent 39670fe commit 929a641

5 files changed

Lines changed: 198 additions & 57 deletions

File tree

docs/arrayfire.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ div.scaled > img
7070

7171
div.scaled > img:hover
7272
{
73+
z-index : 255; /* Hovered image to be shown on top of all */
74+
background : #ffffff;
75+
border : 1px solid #000000;
7376
-ms-transform : scale(2, 2);
7477
-webkit-transform : scale(2, 2);
7578
-moz-transform : scale(2, 2);

docs/details/signal.dox

Lines changed: 181 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ if a and b are the coefficients.
1010
Another way to think about it is that the filter kernel is centered on each pixel in a,
1111
and the output for that pixel or data point is the sum of the products.
1212

13-
Depending on the dimensions of the input signal and the filter signal, any one of the following
13+
Depending on the size of the signal and the filter, any one of the following
1414
batch mode convolutions take place.
1515

1616
- **No Batch** - Single filter applied to single input.
1717
- **Filter is Batched** - Many filters applied on same input
1818
- **Signal is Batched** - Single filter applied to a set of inputs.
1919
- **Identical Batches** - A set of filters applied onto to a set of inputs in one-to-one correspondence.
20-
- **Non overlapping Batches** - All batched filters are applied to all batched signals. The batch dimension of Signal and Filter **should not** be the same.
20+
- **Non overlapping Batches** - All batched filters are applied to all batched signals. The batch
21+
axis of Signal and Filter **should not** be the same.
2122

22-
Non overlapping batch mode is not supported in spatial mode i.e. if the user passes \ref
23-
AF_CONV_SPATIAL explicitly to the functions.
23+
\note All non-overlapping(interleaved) convolutions default to frequency domain
24+
\ref AF_CONV_FREQ irrespective of the provided convolution mode argument.
2425

2526

2627
\page signal_func_fft_desc fft
@@ -56,23 +57,32 @@ This version of convolution function delegates the call to respective
5657
1D, 2D or 3D convolution functions internally.
5758

5859
Convolution dimensionality is \f$ \min (sd, fd) \f$ where sd & fd are dimensionality of
59-
signal and filter respectively. This formulation only decides the dimensionality
60-
of convolution. Please check the respective convolve (hyperlinked below) function
61-
documentation to find out the kind of batch operations possible.
60+
signal and filter respectively. This formulation only decides the dimensionality of convolution.
61+
62+
Given below are some examples on how convolution dimensionality is computed.
63+
64+
| Signal Size | Filter Size | Input Rank | Filter Rank | Convolve Dimensionality |
65+
|:--------------:|:--------------:|:----------:|:-----------:|:-------------------------:|
66+
| \dims{m,n,1,1} | \dims{m,1,1,1} | 2 | 1 | \f$ min(2, 1) => \f$ 1D |
67+
| \dims{m,1,1,1} | \dims{m,n,1,1} | 1 | 2 | \f$ min(1, 2) => \f$ 1D |
68+
| \dims{m,n,1,1} | \dims{m,n,1,1} | 2 | 2 | \f$ min(2, 2) => \f$ 2D |
69+
| \dims{m,n,1,1} | \dims{m,n,p,1} | 2 | 3 | \f$ min(2, 3) => \f$ 2D |
70+
| \dims{m,n,1,p} | \dims{m,n,1,q} | 4 | 4 | 3D |
71+
| \dims{m,n,p,1} | \dims{m,n,q,1} | 3 | 3 | \f$ min(3, 3) => \f$ 3D |
72+
73+
\note In the cases similar to the fifth row of the above table,
74+
signal and filter are of rank 4, the function delegates the
75+
operation to three dimensional convolution \ref signal_func_convolve3
76+
77+
If the operation you intend to perform doesn't align with what this
78+
function does, please check the rank specific convolve functions (hyperlinked below)
79+
documentation to find out more.
80+
6281
- \ref signal_func_convolve1
6382
- \ref signal_func_convolve2
6483
- \ref signal_func_convolve3
6584

66-
Given below are some examples.
6785

68-
| Input Dimensions | Filter Dimensions | Convolve Dimension |
69-
|:----------------:|:-----------------:|:------------------:|
70-
| [m n 1 1] | [m 1 1 1] | 1D |
71-
| [m 1 1 1] | [m n 1 1] | 1D |
72-
| [m n 1 1] | [m n 1 1] | 2D |
73-
| [m n 1 1] | [m n p 1] | 2D |
74-
| [m n 1 p] | [m n 1 q] | 3D |
75-
| [m n p 1] | [m n q 1] | 3D |
7686

7787

7888
\defgroup signal_func_convolve_sep Separable 2D Convolution
@@ -117,17 +127,24 @@ can be decomposed into two vectors shown below.
117127

118128
\copydoc signal_func_conv_desc
119129

120-
For one dimensional signals(lets say m is size of 0th dimension), below batch operations are possible.
130+
For one dimensional signals (lets say m is size of 0th axis), below batch operations are possible.
131+
132+
| Signal Size | Filter Size | Output Size | Batch Mode | Description |
133+
| :------------: | :------------: | :------------: | :----------------------: | :----------------------------------------------------------------- |
134+
| \dims{m,1,1,1} | \dims{m,1,1,1} | \dims{m,1,1,1} | No Batch | Output will be a single convolved array |
135+
| \dims{m,1,1,1} | \dims{m,n,1,1} | \dims{m,n,1,1} | Filter is Batched | n filters applied to same input |
136+
| \dims{m,n,1,1} | \dims{m,1,1,1} | \dims{m,n,1,1} | Signal is Batched | 1 filter applied to n inputs |
137+
| \dims{m,n,p,q} | \dims{m,n,p,q} | \dims{m,n,p,q} | Identical Batches | n*p*q filters applied to n*p*q inputs in one-to-one correspondence |
138+
| \dims{m,n,1,1} | \dims{m,1,p,q} | \dims{m,n,p,q} | Non-overlapping batches | p*q filters applied to n inputs to produce n x p x q results |
121139

122-
| Input Signal Dimensions | Filter Dimensions | Output Dimensions | Batch Mode | Description |
123-
| :-----------------------: | :-----------------: | :-----------------: | :-----------------------: | :----------------------------------------------------------------- |
124-
| [m 1 1 1] | [m 1 1 1] | [m 1 1 1] | No Batch | Output will be a single convolved array |
125-
| [m 1 1 1] | [m n 1 1] | [m n 1 1] | Filter is Batched | n filters applied to same input |
126-
| [m n 1 1] | [m 1 1 1] | [m n 1 1] | Signal is Batched | 1 filter applied to n inputs |
127-
| [m n p q] | [m n p q] | [m n p q] | Identical Batches | n*p*q filters applied to n*p*q inputs in one-to-one correspondence |
128-
| [m n 1 1] | [m 1 p q] | [m n p q] | Non-overlapping batches | p*q filters applied to n inputs to produce n x p x q results |
140+
There are various other permutations of signal and filter sizes that fall under
141+
the category of non-overlapping batch mode that are not listed in the above
142+
table. For any signal and filter size combination to fall under the
143+
non-overlapping batch mode, they should satisfy one of the following conditions.
144+
- Signal and filter size along a given batch axis (\f$ > 1 \f$) should be same.
145+
- Either signal size or filter size along a given batch axis (\f$ > 1 \f$) should be equal to one.
129146

130-
The last entry in the table has more permutations than shown here.
147+
\note For the above tabular illustrations, we assumed \ref af_conv_mode is \ref AF_CONV_DEFAULT.
131148

132149

133150

@@ -138,31 +155,140 @@ The last entry in the table has more permutations than shown here.
138155

139156
\copydoc signal_func_conv_desc
140157

141-
For two dimensional signals, the following are the possible batch operations
142-
possible. Lets say m & n as sizes along the 0th & 1st dimensions respectively
143-
and p & q are the some integral numbers greater than one.
158+
A detailed explanation of each batch mode for 2D convolutions is provided below.
159+
Given below are definitions of variables and constants that are used to
160+
facilitate easy illustration of the operations.
161+
162+
- \f$[M\quad N]\f$, \f$[A\quad B]\f$ are signal, filter sizes along
163+
\f$0^{th}\f$ & \f$1^{st}\f$ axes respectively.
164+
- \f$P\f$ and \f$Q\f$ are two constants, integers greater than one.
165+
- \f$ p \f$ is an integer variable with range \f$ \ 0 \leq p < P \f$.
166+
- \f$ q \f$ is an integer variable with range \f$ \ 0 \leq q < Q \f$.
167+
- O, S and F are notations for Output, Signal and Filter respectively.
168+
169+
We have also used images to showcase some examples which follow the
170+
below notation.
171+
172+
- Each blue line is a two dimensional matrix.
173+
- Each orange line indicates a full 2d convolution operation.
174+
- Suffix of each letter indicates indices along \f$ 3^{rd}\f$ and \f$ 4^{th}\f$
175+
axes in the order of appearance from left to right in the suffix.
176+
- O, S and F are notations for Output, Signal and Filter respectively.
177+
178+
### No Batch
179+
180+
Given below is an example of no batch mode.
181+
182+
\image html "conv_docs_images/basic.png" "Single 2d convolution with 2d filter"
183+
184+
For input size \dims{M,N,1,1} and filter size \dims{A,B,1,1}, the following set-builder
185+
notation gives a formal definition of all convolutions performed in this mode.
186+
187+
\shape_eq{O,M,N,1,1} = \convolve_eq{\shape_t{S,M,N,1,1},\shape_t{F,A,B,1,1}}
188+
189+
190+
### Batched Filter
191+
192+
Given below is an example of filter batch mode.
193+
194+
\image html "conv_docs_images/filter.png" "Single signal convolved with many filters independently"
195+
196+
For input size \dims{M,N,1,1} and filter size \dims{A,B,P,1}, the following set-builder
197+
notation gives a formal definition of all convolutions performed in this mode.
198+
199+
\shape_eq{O,M,N,P,1} = \set_eq{\convolve_t{\shape_t{S,M,N,1,1},\shape_t{f,A,B,p,1}}, \forall \shape_t{f,A,B,p,1} \in \shape_t{F,A,B,P,1}}
200+
201+
202+
### Batched Signal
203+
204+
Given below is an example of signal batch mode.
205+
206+
\image html "conv_docs_images/signal.png" "Single filter convolved with many signals independently"
207+
208+
For input size \dims{M,N,P,1} and filter size \dims{A,B,1,1}, the following set-builder
209+
notation gives a formal definition of all convolutions performed in this mode.
210+
211+
\shape_eq{O,M,N,P,1} = \set_eq{\convolve_t{\shape_t{s,M,N,p,1},\shape_t{F,A,B,1,1}}, \forall \shape_t{s,M,N,p,1} \in \shape_t{S,M,N,P,1}}
212+
213+
214+
### Identical Batch Sizes
215+
216+
Given below is an example of identical batch mode.
144217

145-
| Input Signal Dimensions | Filter Dimensions | Output Dimensions | Batch Mode | Description |
146-
| :-----------------------: | :-----------------: | :-----------------: | :-----------------------: | :------------------------------------------------------------- |
147-
| [m n 1 1] | [m n 1 1] | [m n 1 1] | No Batch | Output will be a single convolved array |
148-
| [m n 1 1] | [m n p 1] | [m n p 1] | Filter is Batched | p filters applied to same input |
149-
| [m n p 1] | [m n 1 1] | [m n p 1] | Signal is Batched | 1 filter applied to p inputs |
150-
| [m n p q] | [m n p q] | [m n p q] | Identical Batches | p*q filters applied to p*q inputs in one-to-one correspondence |
151-
| [m n p 1] | [m n 1 q] | [m n p q] | Non-overlapping batches | q filters applied to p inputs in to produce p x q results |
152-
| [m n 1 p] | [m n q 1] | [m n q p] | Non-overlapping batches | q filters applied to p inputs in to produce q x p results |
218+
\image html "conv_docs_images/identical.png" "Many signals convolved with many filters in one-on-one manner"
153219

154-
* Batching behavior of convolve2_nn functions
220+
For input size \dims{M,N,P,Q} and filter size \dims{A,B,P,Q}, the following set-builder
221+
notation gives a formal definition of all convolutions performed in this mode.
222+
223+
\shape_eq{O,M,N,P,Q} = \set_eq{\convolve_t{\shape_t{s,M,N,p,q},\shape_t{f,A,B,p,q}}, \forall \shape_t{s,M,N,p,q} \in \shape_t{S,M,N,P,Q} \land \forall \shape_t{f,M,N,p,q} \in \shape_t{F,M,N,P,Q}}
224+
225+
226+
### Non-overlapping Batches
227+
228+
Four different kinds of signal and filter size combinations are handled in this batch mode. Each one
229+
of them are explained in respective sections below.
230+
231+
#### Combination 1
232+
233+
For input size \dims{M,N,P,1} and filter size \dims{A,B,1,Q}, the following set-builder
234+
notation gives a formal definition of all convolutions performed in this mode.
235+
236+
\shape_eq{O,M,N,P,Q} = \set_eq{\set_t{\convolve_t{\shape_t{s,M,N,p,1},\shape_t{f,A,B,1,q}}, \forall \shape_t{s,M,N,p,1} \in \shape_t{S,M,N,P,1}}, \forall \shape_t{f,A,B,1,q} \in \shape_t{F,A,B,1,Q}}
237+
238+
Given below is an example of this batch mode.
239+
240+
\image html "conv_docs_images/non-overlapping_1.png"
241+
242+
#### Combination 2
243+
244+
For input size \dims{M,N,P,1} and filter size \dims{A,B,P,Q}, the following set-builder
245+
notation gives a formal definition of all convolutions performed in this mode.
246+
247+
\shape_eq{O,M,N,P,Q} = \set_eq{\set_t{\convolve_t{\shape_t{s,M,N,p,1},\shape_t{f,A,B,p,q}}, \forall \shape_t{f,A,B,p,q} \in \shape_t{F,A,B,P,Q}}, \forall \shape_t{s,M,N,p,1} \in \shape_t{S,M,N,P,1}}
248+
249+
Given below is an example of this batch mode.
250+
251+
\image html "conv_docs_images/non-overlapping_2.png"
252+
253+
#### Combination 3
254+
255+
For input size \dims{M,N,1,P} and filter size \dims{A,B,Q,1}, the following set-builder
256+
notation gives a formal definition of all convolutions performed in this mode.
257+
258+
\shape_eq{O,M,N,Q,P} = \set_eq{\set_t{\convolve_t{\shape_t{s,M,N,1,p},\shape_t{f,A,B,q,1}}, \forall \shape_t{s,M,N,1,p} \in \shape_t{S,M,N,1,P}}, \forall \shape_t{f,A,B,q,1} \in \shape_t{F,A,B,Q,1}}
259+
260+
Given below is an example of this batch mode.
261+
262+
\image html "conv_docs_images/non-overlapping_3.png"
263+
264+
#### Combination 4
265+
266+
For input size \dims{M,N,P,Q} and filter size \dims{A,B,P,1}, the following set-builder
267+
notation gives a formal definition of all convolutions performed in this mode.
268+
269+
\shape_eq{O,M,N,P,Q} = \set_eq{\set_t{\convolve_t{\shape_t{s,M,N,p,q},\shape_t{f,A,B,p,1}}, \forall \shape_t{s,M,N,p,q} \in \shape_t{S,M,N,P,Q}}, \forall \shape_t{f,A,B,p,1} \in \shape_t{F,A,B,P,1}}
270+
271+
Given below is an example of this batch mode.
272+
273+
\image html "conv_docs_images/non-overlapping_4.png"
274+
275+
276+
The batching behavior of convolve2NN functions(\ref af_convolve2_nn() and
277+
\ref convolve2NN() ) is different from convolve2. The new functions can perform 2D
278+
convolution on 3D signals and filters in a way that is more aligned with
279+
convolutional neural networks.
280+
281+
| Signal Size | Filter Size | Output Size | Batch Mode | Description |
282+
| :-----------------: | :-----------------: | :-----------------: | :------------: | :-------------------------------------------------- |
283+
| \dims{M, N, 1, 1} | \dims{M, N, 1, 1} | \dims{M, N, 1, 1} | No Batch | Output will be a single convolved array |
284+
| \dims{M, N, 1, 1} | \dims{M, N, P, 1} | \dims{M, N, P, 1} | *Invalid* | Size along second axis should be same |
285+
| \dims{M, N, P, 1} | \dims{M, N, 1, 1} | \dims{M, N, P, 1} | *Invalid* | Size along second axis should be same |
286+
| \dims{M, N, P, 1} | \dims{M, N, P, 1} | \dims{M, N, 1, 1} | No Batch | 3D Signal and 3D filter convoled to 2D result |
287+
| \dims{M, N, P, Qs} | \dims{M, N, P, Qf} | \dims{M, N, Qf, Qs} | Batch Qs * Qf | Qs signals and Qf filters to create Qs * Qf results |
288+
289+
\note For the above tabular illustrations, we will assume \ref af_conv_mode is \ref AF_CONV_DEFAULT.
155290

156-
Batching behavior in the new convolutions functions have changed. These
157-
functions can perform a 2D convolution on 3D signal and filters.
158291

159-
| Input Signal Dimensions | Filter Dimensions | Output Dimensions | Batch Mode | Description |
160-
| :-----------------------: | :-----------------: | :-----------------: | :-----------------------: | :-------------------------------------------------------- |
161-
| [m n 1 1] | [m n 1 1] | [m n 1 1] | No Batch | Output will be a single convolved array |
162-
| [m n 1 1] | [m n p 1] | [m n p 1] | *Invalid d2 must be same* | N/A |
163-
| [m n p 1] | [m n 1 1] | [m n p 1] | *Invalid Batch* | N/A |
164-
| [m n p 1] | [m n p 1] | [m n 1 1] | No Batch | 3D Signal and 3D filter convoled to 2D result |
165-
| [m n p qs] | [m n p qf] | [m n qf qs] | Batch qs * qf | qs signals and qf filsters to create qs * qf results |
166292

167293
\defgroup signal_func_convolve3 3D Convolutions
168294
\ingroup convolve_mat
@@ -171,15 +297,17 @@ functions can perform a 2D convolution on 3D signal and filters.
171297

172298
\copydoc signal_func_conv_desc
173299

174-
For three dimensional inputs with m, n & p sizes along the 0th, 1st & 2nd dimensions
300+
For three dimensional inputs with m, n & p sizes along the 0th, 1st & 2nd axes
175301
respectively, given below are the possible batch operations.
176302

177-
| Input Signal Dimensions | Filter Dimensions | Output Dimensions | Batch Mode | Description |
178-
| :-----------------------: | :-----------------: | :-----------------: | :-----------------------: | :------------ |
179-
| [m n p 1] | [a b c 1] | [m n p 1] | No Batch | Output will be a single convolve array |
180-
| [m n p 1] | [a b c d] | [m n p d] | Filter is Batched | d filters applied to same input |
181-
| [m n p q] | [a b c 1] | [m n p q] | Signal is Batched | 1 filter applied to q inputs |
182-
| [m n p k] | [a b c k] | [m n p k] | Identical Batches | k filters applied to k inputs in one-to-one correspondence |
303+
| Signal Size | Filter Size | Output Size | Batch Mode | Description |
304+
| :----------------: | :----------------: | :----------------: | :----------------: |:-----------------------------------------------------------|
305+
| \dims{m, n, p, 1} | \dims{a, b, c, 1} | \dims{m, n, p, 1} | No Batch | Output will be a single convolve array |
306+
| \dims{m, n, p, 1} | \dims{a, b, c, d} | \dims{m, n, p, d} | Filter is Batched | d filters applied to same input |
307+
| \dims{m, n, p, q} | \dims{a, b, c, 1} | \dims{m, n, p, q} | Signal is Batched | 1 filter applied to q inputs |
308+
| \dims{m, n, p, k} | \dims{a, b, c, k} | \dims{m, n, p, k} | Identical Batches | k filters applied to k inputs in one-to-one correspondence |
309+
310+
\note For the above tabular illustrations, we assumed \ref af_conv_mode is \ref AF_CONV_DEFAULT.
183311

184312

185313

0 commit comments

Comments
 (0)