@@ -7,6 +7,20 @@
77{-# LANGUAGE MultiParamTypeClasses #-}
88{-# LANGUAGE FlexibleInstances #-}
99{-# LANGUAGE FlexibleContexts #-}
10+{-|
11+Module : Grenade.Layers.Deconvolution
12+Description : Deconvolution layer
13+Copyright : (c) Huw Campbell, 2016-2017
14+License : BSD2
15+Stability : experimental
16+
17+A deconvolution layer is in many ways a convolution layer in reverse.
18+It learns a kernel to apply to each pixel location, spreading it out
19+into a larger layer.
20+
21+This layer is important for image generation tasks, such as GANs on
22+images.
23+-}
1024module Grenade.Layers.Deconvolution (
1125 Deconvolution (..)
1226 , Deconvolution' (..)
@@ -30,42 +44,37 @@ import Grenade.Layers.Internal.Convolution
3044import Grenade.Layers.Internal.Update
3145
3246-- | A Deconvolution layer for a neural network.
33−-- This uses the im2col Deconvolution trick popularised by Caffe, which essentially turns the
34−-- many, many, many, many loop Deconvolution into a single matrix multiplication.
35−--
36−-- The Deconvolution layer takes all of the kernels for the Deconvolution, which are flattened
37−-- and then put into columns in the matrix.
47+-- This uses the im2col Convolution trick popularised by Caffe.
3848--
39−-- The kernel size dictates which input and output sizes will "fit". Fitting the equation:
40−-- `out = (in - kernel) / stride + 1` for both dimensions.
49+-- The Deconvolution layer is a way of spreading out a single response
50+-- into a larger image, and is useful in generating images.
4151--
42−-- One probably shouldn't build their own layer, but rather use the randomDeconvolution function.
4352data Deconvolution :: Nat -- Number of channels, for the first layer this could be RGB for instance.
44− -> Nat -- Number of filters, this is the number of channels output by the layer.
45− -> Nat -- The number of rows in the kernel filter
46− -> Nat -- The number of column in the kernel filter
47− -> Nat -- The row stride of the Deconvolution filter
48− -> Nat -- The columns stride of the Deconvolution filter
49− -> * where
53+ -> Nat -- Number of filters, this is the number of channels output by the layer.
54+ -> Nat -- The number of rows in the kernel filter
55+ -> Nat -- The number of column in the kernel filter
56+ -> Nat -- The row stride of the Deconvolution filter
57+ -> Nat -- The columns stride of the Deconvolution filter
58+ -> * where
5059 Deconvolution :: ( KnownNat channels
51− , KnownNat filters
52− , KnownNat kernelRows
53− , KnownNat kernelColumns
54− , KnownNat strideRows
55− , KnownNat strideColumns
56− , KnownNat kernelFlattened
57− , kernelFlattened ~ (kernelRows * kernelColumns * filters))
58− => !(L kernelFlattened channels) -- The kernel filter weights
59− -> !(L kernelFlattened channels) -- The last kernel update (or momentum)
60− -> Deconvolution channels filters kernelRows kernelColumns strideRows strideColumns
60+ , KnownNat filters
61+ , KnownNat kernelRows
62+ , KnownNat kernelColumns
63+ , KnownNat strideRows
64+ , KnownNat strideColumns
65+ , KnownNat kernelFlattened
66+ , kernelFlattened ~ (kernelRows * kernelColumns * filters))
67+ => !(L kernelFlattened channels) -- The kernel filter weights
68+ -> !(L kernelFlattened channels) -- The last kernel update (or momentum)
69+ -> Deconvolution channels filters kernelRows kernelColumns strideRows strideColumns
6170
6271data Deconvolution' :: Nat -- Number of channels, for the first layer this could be RGB for instance.
63− -> Nat -- Number of filters, this is the number of channels output by the layer.
64− -> Nat -- The number of rows in the kernel filter
65− -> Nat -- The number of column in the kernel filter
66− -> Nat -- The row stride of the Deconvolution filter
67− -> Nat -- The columns stride of the Deconvolution filter
68− -> * where
72+ -> Nat -- Number of filters, this is the number of channels output by the layer.
73+ -> Nat -- The number of rows in the kernel filter
74+ -> Nat -- The number of column in the kernel filter
75+ -> Nat -- The row stride of the Deconvolution filter
76+ -> Nat -- The columns stride of the Deconvolution filter
77+ -> * where
6978 Deconvolution' :: ( KnownNat channels
7079 , KnownNat filters
7180 , KnownNat kernelRows