@@ -7,6 +7,20 @@
7{-# LANGUAGE MultiParamTypeClasses #-}
7{-# LANGUAGE MultiParamTypeClasses #-}
8{-# LANGUAGE FlexibleInstances #-}
8{-# LANGUAGE FlexibleInstances #-}
9{-# LANGUAGE FlexibleContexts #-}
9{-# LANGUAGE FlexibleContexts #-}
11+Module : Grenade.Layers.Deconvolution
12+Description : Deconvolution layer
13+Copyright : (c) Huw Campbell, 2016-2017
15+Stability : experimental
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
21+This layer is important for image generation tasks, such as GANs on
10module Grenade.Layers.Deconvolution (
24module Grenade.Layers.Deconvolution (
11 Deconvolution (..)
25 Deconvolution (..)
12 , Deconvolution' (..)
26 , Deconvolution' (..)
@@ -30,42 +44,37 @@ import Grenade.Layers.Internal.Convolution
30import Grenade.Layers.Internal.Update
44import Grenade.Layers.Internal.Update
32-- | A Deconvolution layer for a neural network.
46-- | A Deconvolution layer for a neural network.
33−-- This uses the im2col Deconvolution trick popularised by Caffe, which essentially turns the
47+-- This uses the im2col Convolution trick popularised by Caffe.
34−-- many, many, many, many loop Deconvolution into a single matrix multiplication.
36−-- The Deconvolution layer takes all of the kernels for the Deconvolution, which are flattened
37−-- and then put into columns in the matrix.
39−-- The kernel size dictates which input and output sizes will "fit". Fitting the equation:
49+-- The Deconvolution layer is a way of spreading out a single response
40−-- `out = (in - kernel) / stride + 1` for both dimensions.
50+-- into a larger image, and is useful in generating images.
42−-- One probably shouldn't build their own layer, but rather use the randomDeconvolution function.
43data Deconvolution :: Nat -- Number of channels, for the first layer this could be RGB for instance.
52data 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.
53+ -> Nat -- Number of filters, this is the number of channels output by the layer.
45− -> Nat -- The number of rows in the kernel filter
54+ -> Nat -- The number of rows in the kernel filter
46− -> Nat -- The number of column in the kernel filter
55+ -> Nat -- The number of column in the kernel filter
47− -> Nat -- The row stride of the Deconvolution filter
56+ -> Nat -- The row stride of the Deconvolution filter
48− -> Nat -- The columns stride of the Deconvolution filter
57+ -> Nat -- The columns stride of the Deconvolution filter
49− -> * where
58+ -> * where
50 Deconvolution :: ( KnownNat channels
59 Deconvolution :: ( KnownNat channels
51− , KnownNat filters
60+ , KnownNat filters
52− , KnownNat kernelRows
61+ , KnownNat kernelRows
53− , KnownNat kernelColumns
62+ , KnownNat kernelColumns
54− , KnownNat strideRows
63+ , KnownNat strideRows
55− , KnownNat strideColumns
64+ , KnownNat strideColumns
56− , KnownNat kernelFlattened
65+ , KnownNat kernelFlattened
57− , kernelFlattened ~ (kernelRows * kernelColumns * filters))
66+ , kernelFlattened ~ (kernelRows * kernelColumns * filters))
58− => !(L kernelFlattened channels) -- The kernel filter weights
67+ => !(L kernelFlattened channels) -- The kernel filter weights
59− -> !(L kernelFlattened channels) -- The last kernel update (or momentum)
68+ -> !(L kernelFlattened channels) -- The last kernel update (or momentum)
60− -> Deconvolution channels filters kernelRows kernelColumns strideRows strideColumns
69+ -> Deconvolution channels filters kernelRows kernelColumns strideRows strideColumns
62data Deconvolution' :: Nat -- Number of channels, for the first layer this could be RGB for instance.
71data 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.
72+ -> Nat -- Number of filters, this is the number of channels output by the layer.
64− -> Nat -- The number of rows in the kernel filter
73+ -> Nat -- The number of rows in the kernel filter
65− -> Nat -- The number of column in the kernel filter
74+ -> Nat -- The number of column in the kernel filter
66− -> Nat -- The row stride of the Deconvolution filter
75+ -> Nat -- The row stride of the Deconvolution filter
67− -> Nat -- The columns stride of the Deconvolution filter
76+ -> Nat -- The columns stride of the Deconvolution filter
68− -> * where
77+ -> * where
69 Deconvolution' :: ( KnownNat channels
78 Deconvolution' :: ( KnownNat channels
70 , KnownNat filters
79 , KnownNat filters
71 , KnownNat kernelRows
80 , KnownNat kernelRows